ModuleNotFoundError: No module named 'django.urls'

随声附和 提交于 2019-12-13 17:21:38

问题


Whenever I try to run "python manage.py runserver" in Powershell as admin, I get an ModuleNotFoundError: No module named 'django.urls'. Can somebody help me please?!

I'm using django 1.9 and python 3.6


IN POWERSHELL

File "C:\Users\MAHE\PycharmProjects\website_new\website_new\urls.py", line 3,
from django.urls import path
ModuleNotFoundError: No module named 'django.urls'

IN URLS.PY:

from django.contrib import admin

from django.urls import path

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

回答1:


I think this should work!

from django.urls import path

It was introduced in django 2.0, you need to upgrade your django version for it to work. Kindly check the documentation for django 2.0 https://docs.djangoproject.com/en/2.0/ref/urls/




回答2:


from django.urls import path

is new feature of Django 2.0 , so upgrade your Django please...




回答3:


Since, you are already using python 3.6 so you need to upgrade django to latest version which is greater than 2. For those who are using python 2.7, python2.7 don't support django 2 so you can't install django.urls.

On PowerShell

pip install -U django

Verification

PS C:\Users\xyz> python
Python 3.6.6 |Anaconda, Inc.| (default, Jul 25 2018, 15:27:00) [MSC v.1910 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.urls import path
>>>

As next prompt came, it means it is installed now and ready to use.



来源:https://stackoverflow.com/questions/47711703/modulenotfounderror-no-module-named-django-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!