Deesha
Deesha

Reputation: 37

Django Name Error

I have the following code in my urls.py

from django.conf.urls import url
from django.contrib import admin
from django.conf.urls import include
urlpatterns = [
    url(r'^testModule/',include(testModule.urls)),
    url(r'^admin/', admin.site.urls),
]

and testModule is my app name which includes :

from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$',views.index,name='index'),
]

And my views.py is

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello")
# Create your views here.

However, i get the following error while running the server:

line 20: url(r'^testModule/',include(testModule.urls)), NameError: name 'testModule' is not defined

Upvotes: 0

Views: 222

Answers (2)

Nkoroi
Nkoroi

Reputation: 1

Had the same problem but solved it like this:

  • add "import testModule" to your urls.py
  • add "from django.conf.urls import url" to your urls.py in the app directory, in this case testModule

Once done you will get a "Page not found at/" error when you reload 127.0.0.1:8000. This is bacause the url to your app is actually at 127.0.0.1:8000/testModule

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 600059

You haven't imported testModule in your main urls.

Upvotes: 2

Related Questions