Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Build Your Routes

In this lesson, you’re going to look at how to build routes. In the previous lesson, you tried a URL that doesn’t exist and got an error message that told you to check portfolio.url.

When you check that file, you can see all of the URL patterns that exist there. If you try to go to /projects, then you’ll see that it isn’t registered anywhere, so Django doesn’t know what to do with it. Fortunately, Django provides a lot of useful information in the comment at the top of that file.

Comments & Discussion

Pygator on Oct. 12, 2019

I get this mistake when rerunning the server after adding to the urlpatterns:

File “<frozen importlib._bootstrap>”, line 1006, in _gcd_import File “<frozen importlib._bootstrap>”, line 983, in _find_and_load File “<frozen importlib._bootstrap>”, line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named ‘projects.urls’

Martin Breuss RP Team on Oct. 16, 2019

My guess from looking at your traceback is that you are somewhere referencing a urls.py file in a projects app folder that might not exist or be incorrectly linked.

Jon Lee on Jan. 13, 2020

I had a similar issue as Pygator when using ‘projects.urls’. The following seemed to solve the issue.

(in portfolio/urls.py)

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

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

Martin Breuss RP Team on Jan. 14, 2020

Hello again, thanks for your comments. @Pygator, as a follow-up: did you make sure that the file projects/urls.py exists? You shouldn’t have created it yet at the beginning of this video, that’s why at ~3:11 I am handling the same error that you are talking about. This is expected if the file doesn’t exist yet, since Django can’t find the (non-existent) file.

@Jon Lee: In your case you already created the file, since you are able to import it in the way you showed. I would suggest, however, to stick with the way that Django proposes to handle the import:

path('projects/', include('projects.urls')

This avoids the necessity to import the file explicitly.

I assume that you were running into a different issue than @Pygator. Can you give it another go with the proposed way of linking to the app’s urls.py file that is mentioned in the video and in this post, and follow-up with the exact error message you are receiving, in case you run into one?

Please note that 'projects.urls' is indeed a string.

Jon Lee on Jan. 14, 2020

Hi Martin. I was running into another issue but that seems to have been solved now that you pointed out that ‘projects.urls’ is supposed to be a string. I didn’t wrap that section in quotes first time around. Thank you :)

Martin Breuss RP Team on Jan. 17, 2020

Great, glad to here you managed to fix it! 👏

Hi, Martin. When I tried to run the server, it gave me the error:

March 19, 2020 - 18:39:33
Django version 3.0.4, using settings 'portfolio.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Not Found: /
[19/Mar/2020 18:39:42] "GET / HTTP/1.1" 404 2033

However, I did implement

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

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

correctly as you did in porfolio/urls.py. Can you help me to fix this error? Thank you very much.

Martin Breuss RP Team on March 19, 2020

If you look closely at the error, it tells you what URL path it didn’t find:

Not Found: /

You did not create a urlpattern for the empty base URL (and neither did I when building out the project). So in short: your error is expected and if you navigate to one of the defined urlpatterns (/admin or /projects) you should see a page pop up :)

It works. Thanks Martin.

budescueftimie on March 26, 2020

after you import views you restart your server in the terminal, how do you do it? i cant write in my terminal. i have AttributeError: module ‘projects.views’ has no attribute ‘project_list’ and under its the blinking square but i cant write . how do you do that??

Martin Breuss RP Team on March 27, 2020

Hi @budescueftimie. Sometimes the development server gets stuck on an error. You can stop it by pressing Ctrl+D or Ctrl+C - or simply by closing your terminal window and opening up a new one.

Restart the server - and you should be good to go :)

budescueftimie on March 29, 2020

thank you, Ctrl+C works, i did not want to have to close and open a new terminal window everytime i get stuck in an error.

Joel Witherspoon on April 28, 2020

@budescueftimie If your keyboard has a function key, hold Ctrl+function and find the BREAK key and press it. The server should then release.

Become a Member to join the conversation.