1

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!

1
  • Hi, I'm the author of PCC. For future reference, you can see the code for the project here. Here's what the urls.py file should look like at this point in the project. The project was originally written with Django 2.2, but I keep the book up to date with each new printing, and everything in the second edition still works at this time. Commented Apr 4, 2022 at 17:42

2 Answers 2

1
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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

this was precisely the error.......... thank you so much for your answer
you are welcome bro! can you just accept it as the answer so any other person having the same problem can solve it. and upvote plz :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.