【发布时间】:2015-11-08 00:05:32
【问题描述】:
我正在阅读 1.8 版的 django 教程,但我遇到了一个错误,我被卡住了,似乎无法弄清楚。我以为我几乎是按照教程学习到 T 的。
我设置了以下树:
.
├── dj_project
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
├── manage.py
└── polls
├── admin.py
├── admin.pyc
├── __init__.py
├── __init__.pyc
├── migrations
│ ├── 0001_initial.py
│ ├── 0001_initial.pyc
│ ├── __init__.py
│ └── __init__.pyc
├── models.py
├── models.pyc
├── tests.py
├── urls.py
├── urls.pyc
├── views.py
└── views.pyc
并且拥有,就像在 polls/urls.py 的教程中一样:
from django.conf.urls import url
from . import views
urlpatterns = {
url(r'^$', views.index, name='index'),
}
对于我的 dj_project/urls.py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
]
在 polls/views.py 我有:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("is there something here?")
所以当我转到<mysite>/polls 时,我看到“这里有什么东西”,但如果我转到<mysite>/admin,我得到错误:TypeError at /admin/ argument to reversed() must be a sequence。如果我从dj_project/urls.py 的 urlpatterns 中删除民意调查,管理员就可以了。
可能是什么问题?我好像搞不懂。
【问题讨论】:
-
你想在任何地方使用
reverse吗?
标签: python django-1.8