AttributeError: 'str' object has no attribute 'regex' django 1.9

前端 未结 4 1204
无人共我
无人共我 2021-02-19 22:28

I am working with django 1.9 and I am currently coding - in Windows Command Prompt - python manage.py makemigrations and the error:

AttributeErr

4条回答
  •  执笔经年
    2021-02-19 22:41

    Firstly, remove the django.conf.urls.handler400 from the middle of the urlpatterns. It doesn't belong there, and is the cause of the error.

    Once the error has been fixed, you can make a couple of changes to update your code for Django 1.8+

    1. Change urlpatterns to a list, instead of using patterns()

    2. Import the views (or view modules), instead of using strings in your urls()

    3. You are using the same regex for the start and login views. This means you won't be able to reach the login views. One fix would be to change the regex for the login view to something like ^login/$

    Putting that together, you get something like:

    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, name="home"),
      url(r'^admin/', include(admin.site.urls)),
      url(r'^login/$', 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'),
    ]
    

提交回复
热议问题