Hello folks,
I am completely new in Python programming, and at beginning of the day, I am having some issues.
Hope you guys will help me pass through the issue.
The error shows on my CMD:
path(r'^admin/', admin.site.urls),
NameError: name 'path' is not defined
MySite:
urls.py-AboutUs
Quote:from django.conf.urls import url
from.import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
views.py
Quote:from django.http import httpresponse
def index(request):
return httpresponse ("<h1>Hello About us</>")
urls.py-My1stDjangoSite
Quote:from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
path(r'^admin/', admin.site.urls),
path(r'^aboutus/', include('aboutus.urls')),
IDE: Atom
You have to import the
path
module:
from django.urls import path
BTW, what version of Django are you using?
Hello Gontajones,
Thanks for your reply.
Django version is : (2, 1, 0, 'beta', 1)
After I made changes I am getting now different Error (as you suggested).
Quote: path(r'^aboutus/', include('aboutus.urls')),
File "C:\Python\lib\site-packages\django-2.1b1-py3.6.egg\django\urls\conf.py",
line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'aboutus'
What is
aboutus
? It is an app, right?
You have to import it too.
import aboutus
Yes, Aboutus is an App. where should I add this "import aboutus " ? on root urls.py or under my apps ulrs.py?
Sorry if you found this is silly questions, i am new.
Where do you call it?
Usually is on your root urls.py (project urls.py).
What is the name of the app, AboutUs or abautus?
You have to use the exact name as include('app_name.urls') parameter:
# For app name AboutUs
path('aboutus/', include('AboutUs.urls')
# Or
# For app name aboutus
path('aboutus/', include('aboutus.urls')
And the file urls.py must exists inside the app's folder.
Perfect, Thanks Gontajones
it was Case sensitive
i used, path('aboutus/', include('AboutUs.urls') and after that i was getting
Quote:Request Method: GET
Request URL: http://127.0.0.1:8000/aboutus/
Django Version: 1.3.1
Exception Type: ImportError
Exception Value:
cannot import name HttpResponse
then i changed to
Quote:django.http import HttpResponse
and it works.
Thank you for your time.
Yep, now you got it!
When you use something from external modules, you have to import them.