Python Forum
NameError: Name 'path' is not defined
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError: Name 'path' is not defined
#1
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
Reply
#2
You have to import the path module:

from django.urls import path
BTW, what version of Django are you using?
Reply
#3
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'
Reply
#4
What is aboutus? It is an app, right?

You have to import it too.

import aboutus
Reply
#5
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.
Reply
#6
Where do you call it?
Usually is on your root urls.py (project urls.py).
Reply
#7
Here is the link of Image.
https://ibb.co/de1rGd
please take a look
Thanks
Reply
#8
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.
Reply
#9
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.
Reply
#10
Yep, now you got it!
When you use something from external modules, you have to import them.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NameError :name 'name' is not defined Suzzy_ 4 18,771 Dec-27-2019, 09:04 AM
Last Post: LeanbridgeTech
  NameError: name 'download' is not defined ntdropper 3 11,199 Jan-13-2018, 07:18 AM
Last Post: snippsat
  NameError: name 'bsObj' is not defined Blue Dog 14 15,475 Oct-24-2016, 08:34 AM
Last Post: Blue Dog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020