NameError名称“视图”未定义 [英] NameError name 'Views' is not defined

查看:148
本文介绍了NameError名称“视图”未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

from django.conf.urls import url, patterns, include
from django.contrib import admin
from django.views.generic import TemplateView
from collection import *


#from collection.views import index,thing_detail,edit_thing

urlpatterns = [ 
        url(r'^$', views.index, name='home'),
        url(r'^about/$',TemplateView.as_view(template_name='about.html'),name='about'),
        url(r'^contact/$',TemplateView.as_view(template_name='contact.html'),name='contact'),
        url(r'^things/(?P<slug>[-\w]+)/$', 'views.thing_detail' ,name='thing_detail'),
        url(r'^things/(?P<slug>[-\w]+)/edit/$', 'views.edit_thing',name='edit_thing'), 
        url(r'^admin/', include(admin.site.urls)),
]  

运行服务器后,出现错误 NameError:未定义名称'views'

After running the server there is an error "NameError: name 'views' is not defined"

任何帮助??

推荐答案

您不是即时消息移植您自己的视图。

You aren't importing your own views.

尝试将其添加到您的 urls.py

from . import views

或者如果您是从特定应用程序导入视图,请尝试替换的应用名称

Or if you are importing them from a specific app, try replacing . with the app name

这篇关于NameError名称“视图”未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆