Forums

No module named 'django.urls'

(My english is not the best) Hi, i am triying run my app but give me this error:

ImportError at / No module named 'django.urls' Request Method: GET Request URL: http://jalkhov.pythonanywhere.com/ Django Version: 1.8 Exception Type: ImportError Exception Value: No module named 'django.urls' Exception Location: /home/Jalkhov/my-first-blog/mysite/urls.py in <module>, line 2 Python Executable: /usr/local/bin/uwsgi Python Version: 3.4.3 Python Path: ['/var/www', '.', '', '/var/www', '/home/Jalkhov/my-first-blog/myvenv/lib/python3.4', '/home/Jalkhov/my-first-blog/myvenv/lib/python3.4/plat-x86_64-linux-gnu', '/home/Jalkhov/my-first-blog/myvenv/lib/python3.4/lib-dynload', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/home/Jalkhov/my-first-blog/myvenv/lib/python3.4/site-packages', '/home/Jalkhov/my-first-blog'] Server time: Sun, 1 Jul 2018 19:12:52 -0400

This is my urls.py file

from django.contrib import admin from django.urls import path urlpatterns = [ path('admin/', admin.site.urls), ]

I am new in Django and Python, thanks.

Make sure you're using the same Django version that the code was written for.

Well, what happens is that I'm following a tutorial, I've updated the Django version to 2.0, I've also changed certain things in the settings.py file, all right, the web shows by default that Django has been installed correctly, in the next part of the tutorial where the urls.py file should look like this:

from django.conf.urls import include, url 
from django.contrib import admin

urlpatterns = [ 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'', include('blog.urls')), 
]

It shows me an error which you can appreciate if you visit the website: jalkhov.pythonanywhere.com

The thing is, if you're following a tutorial for one version of Django but you're using a different one, the code is likely to fail for confusing reasons that will make it much harder to learn anything. In particular, the change from Django version 1.11 to 2.0 changed the location of a bunch of functions and classes. If you switch back to using the version of Django specified in the tutorial you'll find things much easier.

Hello,

I'm following tutorial from DjangoGirls and got the same error, it turns out that I had typo in blog/urls.py: "from django.url import path" (missing "s" in url). The point is that you have to make sure to follow all the tutorial correctly and you wont get any error.