我不明白我的Django后端规范有什么问题
These are my urls
from django.contrib import admin
from django.urls import path,include
from django.conf.urls import url
from store import views
urlpatterns = [
url(r'^', include('store.urls')),
url(r'^accounts', include('registration.backends.default.urls')),
path('admin/', admin.site.urls),
]
这是树结构
bookstore
├── bookstore
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-36.pyc
│ │ ├── settings.cpython-36.pyc
│ │ ├── urls.cpython-36.pyc
│ │ └── wsgi.cpython-36.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── db.sqlite3
├── manage.py
├── requirements.txt
└── store
├── admin.py
├── apps.py
├── __init__.py
├── migrations
│ ├── 0001_initial.py
│ ├── 0002_auto_20180604_0751.py
│ ├── __init__.py
│ └── __pycache__
│ ├── 0001_initial.cpython-36.pyc
│ ├── 0002_auto_20180604_0751.cpython-36.pyc
│ └── __init__.cpython-36.pyc
├── models.py
├── __pycache__
│ ├── admin.cpython-36.pyc
│ ├── __init__.cpython-36.pyc
│ ├── models.cpython-36.pyc
│ ├── urls.cpython-36.pyc
│ └── views.cpython-36.pyc
├── templates
│ ├── registration
│ │ ├── activate.html
│ │ ├── activation_complete.html
│ │ ├── activation_email_subject.txt
│ │ ├── activation_mail.txt
│ │ ├── registration_complete.html
│ │ └── registration_form.html
│ ├── store.html
│ └── template.html
├── tests.py
├── urls.py
└── views.py
现在我试试 python manage.py runserver 我懂了
也在终端显示我
Not Found: /accounts
[05/Jun/2018 09:08:17] "GET /accounts HTTP/1.1" 404 5632
如果我去
url(r'^accounts/', include('registration.backends.default.urls')),
然后我
1. ^accounts/
...
当前路径,帐户,与这些路径中的任何一个都不匹配。
如何解决这个问题? Django后端如何工作? 我使用的是2.0.5版本。
答案 0 :(得分:1)
使用path
代替url
:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('store.urls')),
path('accounts/', include('registration.backends.default.urls')),
path('admin/', admin.site.urls),
]
顺便说一句,如果Django版本< = 1.11,请使用url
。 ({2.0}之后添加path
答案 1 :(得分:0)
尝试使用
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^/', include('store.urls')),
而不是
url(r'^accounts', include('registration.backends.default.urls')),
url(r'^', include('store.urls')),