Home > OS >  NameError: name 'users' is not defined in python django
NameError: name 'users' is not defined in python django

Time:04-05

Hi I'm sorry if this question has been repeatedly asked but I hope that you kindly help me to figure out what is the problem here. I'm following a python crash course book that uses old versions of Django.

I've set up a app called 'users' in my setting so users can make accounts of their own.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #my apps
    'learning_logs',
    'users',
]

and I've included the path in my urls file:

from django.contrib import admin
from django.urls import path, include

app_name = 'learning_logs'

urlpatterns = [
    path('admin/', admin.site.urls),
    path('users/', users.urls),
    path('', include('learning_logs.urls')),
]

and this is the error that I get:

NameError: name 'users' is not defined

and if I do it like this from django.contrib import admin from django.urls import path, include

app_name = 'learning_logs'

urlpatterns = [
    path('admin/', admin.site.urls),
    path('users/', include('users.urls')),
    path('', include('learning_logs.urls')),
]

I get the following error message:

ModuleNotFoundError: No module named 'users.urls'

thank you so much for your time and response!

CodePudding user response:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('users/', include('users.urls')),
    path('', include('learning_logs.urls')),
]

I think this line is causing problems. You need to add 'users.url' inside quotes or else it won't be able to find these urls.

CodePudding user response:

Make Sure that there is a 'urls.py' file in your app.

What you are doing here is that you are trying to make a new url file inside your app so that it will be 'www.your.domain/users/the_url_choose' and to do this you must have a urls.py file instide your app (the folder names 'users')

Inside that urls file you have to copy exactly the main urls file and change it according to your needs for easy site routing

  • Related