我正在使用
django 1.9,我目前正在编码 – 在
Windows命令提示符 – python manage.py makemigrations和错误:
AttributeError:’str’对象没有属性’regex’
我试过编码:
url(r'^$','firstsite.module.views.start',name="home"),url(r'^admin/',include(admin.site.urls)),url(r'^$','django.contrib.auth.views.login',{'template_name': 'login.html'},name='login'),url(r'^signup/$','exam.views.signup',name='signup'),url(r'^signup/submit/$','exam.views.signup_submit',name='signup_submit')
在urls.py中,错误是不断发生的.
这是我第一次在django编码,所以我的专长非常有限.先谢谢你.
这是整个urls.py:
from django.conf.urls import patterns,include,url import django # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() from django.conf.urls.static import static from django.conf import settings urlpatterns = patterns('',# Examples: # url(r'^$','firstsite.views.home',name='home'),# url(r'^firstsite/',include('firstsite.foo.urls')),# Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/',include('django.contrib.admindocs.urls')),# Uncomment the next line to enable the admin: #url(r'^admin/',django.conf.urls.handler400,name='signup_submit'),)
解决方法
首先,从urlpatterns的中间删除django.conf.urls.handler400.它不属于那里,是错误的原因.
一旦错误被修复,您可以进行几个更改来更新Django 1.8的代码
>将urlpatterns更改为列表,而不是使用patterns()
>导入视图(或查看模块),而不是在urls()中使用字符串
>您正在使用相同的正则表达式来启动和登录视图.这意味着您将无法访问登录视图.一个修复是将登录视图的正则表达式更改为^ login / $
把它们放在一起,你会得到如下的东西:
from firstsite.module.views import start from exam import views as exam_views from django.contrib.auth import views as auth_views urlpatterns = [ url(r'^$',start,url(r'^login/$',auth_views.login,exam_views.signup,exam_views.signup_submit,]