所有我试图运行Django应用程序时遇到的错误提示: ImportError:没有模块名称网址。
这是我得到的回溯:
回溯(最近通话最近):文件 “ /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”, 85行 self.result =应用程序(self.environ,self.start_response)文件 “ /Library/Python/2.7/site-packages/django/contrib/staticfiles/handlers.py”, 第64行,致电 返回self.application(环境,start_response)文件“ /Library/Python/2.7/site-packages/django/core/handlers/wsgi.py”,行 168,在致电中 self.load_middleware()文件“ /Library/Python/2.7/site-packages/django/core/handlers/base.py”,行 46,在load_middleware中 mw_instance = mw_class()文件“ /Library/Python/2.7/site-packages/django/middleware/locale.py”,行 23,在 init 中 用于get_resolver(无)中的url_pattern(URL):url_patterns:文件“ /Library/Python/2.7/site-packages/django/core/urlresolvers.py”,行 367,以url_patterns 模式= getattr(self.urlconf_module,“ urlpatterns”,self.urlconf_module)文件 “ /Library/Python/2.7/site-packages/django/core/urlresolvers.py”,行 361,在urlconf_module中 self._urlconf_module = import_module(self.urlconf_name)文件“ /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py”, import_module中的第37行 导入(名称)文件“ /Users/edwardkeselman/Desktop/Work/Crowdview/crowdview/urls.py”,行 20英寸 url(r'^ analysis /',include('data_analysis.urls')),文件“ /Library/Python/2.7/site-packages/django/conf/urls/init.py”,线 28,包括 urlconf_module = import_module(urlconf_module)文件“ /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py”, import_module中的第37行 导入(名称)文件“ /Users/edwardkeselman/Desktop/Work/Crowdview/data_analysis/urls.py”, 第2行 从data_analysis导入视图文件“ /Users/edwardkeselman/Desktop/Work/Crowdview/data_analysis/views.py”中, 第4行 从rest_framework.decorators导入api_view文件“ /Users/edwardkeselman/Library/Python/2.7/lib/python/site-packages/rest_framework/decorators.py”, 第16行 从rest_framework.views导入APIView文件“ /Users/edwardkeselman/Library/Python/2.7/lib/python/site-packages/rest_framework/views.py”, 第16行 来自rest_framework导入异常,状态文件为“ /Users/edwardkeselman/Library/Python/2.7/lib/python/site-packages/rest_framework/exceptions.py”, 第18行,在 从rest_framework.compat导入unicode_to_repr文件“ /Users/edwardkeselman/Library/Python/2.7/lib/python/site-packages/rest_framework/compat.py”, 第21行,在 从django.urls导入(#noqa ImportError:没有名为urls的模块
这是我的urls.py文件:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django import template
from django.conf.urls.i18n import i18n_patterns
urlpatterns = patterns('',
url(r'^', include('coverage.urls')),
url(r'fr/', include('coverage.urls')),
url(r'en/', include('coverage.urls')),
url(r'ru/', include('coverage.urls')),
url(r'zh/', include('coverage.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^accounts/', include('accounts.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^demo/', include('coverage.urls')),
url(r'^ru/demo/', include('coverage.urls')),
url(r'^zh/demo/', include('coverage.urls')),
url(r'^fr/demo/', include('coverage.urls')),
url(r'^en/demo/', include('coverage.urls')),
url(r'^analysis/', include('data_analysis.urls')),
url(r'^telcel_stats/', include('general_stats.urls')),
)
urlpatterns += i18n_patterns(
url(r'^', include('coverage.urls')),
)
template.add_to_builtins('django.templatetags.i18n')
如何解决此问题?
编辑: 在尝试了克里希纳·乔杜里(Krishna Choudhary)的建议答案后,我的“回溯”看起来像这样:
回溯(最近通话最近):文件 “ /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”, 85行 self.result =应用程序(self.environ,self.start_response)文件 “ /Library/Python/2.7/site-packages/django/contrib/staticfiles/handlers.py”, 第64行,致电 返回self.application(环境,start_response)文件“ /Library/Python/2.7/site-packages/django/core/handlers/wsgi.py”,行 168,在致电中 self.load_middleware()文件“ /Library/Python/2.7/site-packages/django/core/handlers/base.py”,行 46,在load_middleware中 mw_instance = mw_class()文件“ /Library/Python/2.7/site-packages/django/middleware/locale.py”,行 23,在 init 中 用于get_resolver(无)中的url_pattern(URL):url_patterns:文件“ /Library/Python/2.7/site-packages/django/core/urlresolvers.py”,行 367,以url_patterns 模式= getattr(self.urlconf_module,“ urlpatterns”,self.urlconf_module)文件 “ /Library/Python/2.7/site-packages/django/core/urlresolvers.py”,行 361,在urlconf_module中 self._urlconf_module = import_module(self.urlconf_name)文件“ /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py”, import_module中的第37行 导入(名称)ImportError:没有名为urls的模块
答案 0 :(得分:1)
我在项目根目录中也遇到类似的问题... django抱怨找不到模块mysite.urls。
结果显示使用默认值设置的settings.py中的ROOT_URLCONF变量设置错误。代替“ mysite.urls”,它应该只是“ urls”
我更改了它,瞧,它起作用了。