在Django 1.9.4中的/ admin /的ImportError

时间:2016-03-26 12:01:48

标签: python django django-admin

我将我的Django版本更新为1.9.4,现在我收到导入错误

No module named views

当我尝试访问Admin-URL时。

django.contrib.admin包含在settings.py

中的Installed_Apps中

如何解决此错误?

Django项目的其余部分工作正常。

错误日志:

  

[26 / Mar / 2016 12:54:02]" GET / admin / HTTP / 1.1" 500 114684   内部服务器错误:/ admin /   Traceback(最近一次调用最后一次):     文件" /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" ;,第149行,在get_response中       response = self.process_exception_by_middleware(e,request)     文件" /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" ;,第147行,在get_response中       response = wrapped_callback(request,* callback_args,** callback_kwargs)     文件" /usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" ;,第265行,在包装器中       return self.admin_view(view,cacheable)(* args,** kwargs)     文件" /usr/local/lib/python2.7/dist-packages/django/utils/decorators.py",第149行,在_wrapped_view中       response = view_func(request,* args,** kwargs)     文件" /usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py",第57行,在_wrapped_view_func中       response = view_func(request,* args,** kwargs)     文件" /usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" ;,第234行,内在       if request.path == reverse(' admin:logout',current_app = self.name):     文件" /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" ;,第568行,反过来       app_list = resolver.app_dict [ns]     文件" /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" ;,第360行,在app_dict中       self._populate()     文件" /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" ;,第316行,在_populate中       对于pattern.reverse_dict中的名称:     文件" /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" ;,第346行,在reverse_dict中       self._populate()     文件" /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" ;,第334行,在_populate中       lookups.appendlist(pattern.callback,(bits,p_pattern,pattern.default_args))     文件" /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" ;,第255行,在回调中       self._callback = get_callable(self._callback_str)     文件" /usr/local/lib/python2.7/dist-packages/django/utils/lru_cache.py" ;,第100行,在包装器中       result = user_function(* args,** kwds)     get_callable中的文件" /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" ;,第115行       mod = import_module(mod_name)     在import_module中输入文件" /usr/lib/python2.7/importlib/ init .py",第37行       导入(名称)   ImportError:没有名为views的模块

的mysite / urls.py

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

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

mysite的/博客/ urls.py

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^view/(?P<slug>[^\.]+)', 'views.view_post', name='view_blog_post'),
   url(r'^category/(?P<slug>[^\.]+)', 'views.view_category', name='view_blog_category'),
]

mysite的/博客/ admin.py

from django.contrib import admin
from blog.models import Post, Category

class PostAdmin(admin.ModelAdmin):
    exclude = ['posted']
    prepopulated_fields = {'slug': ('title',)}

class CategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}

admin.site.register(Post, PostAdmin)
admin.site.register(Category, CategoryAdmin)

1 个答案:

答案 0 :(得分:1)

好的,我找到了解决方案。

错误发生在mysite/blog/urls.py

我刚删除了

中的引号

url(r'^view/(?P<slug>[^\.]+)', views.view_post, name='view_blog_post'),