这是urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^/', include('main.urls', namespace='Home')),
]
这是views.py
from django.shortcuts import render,HttpResponse,render_to_response,HttpResponseRedirect
from django.views.generic import TemplateView
from main.models import *
class leaflet(TemplateView):
template_name = "file.html"
当我编写此代码模板未显示时,会抛出错误:
__init__()
需要1个位置参数,但有2个被赋予"
你能在我的代码中找到错误吗?
答案 0 :(得分:0)
您需要在urlpatterns中添加leaflet.as_view()
urls.py
from django.conf.urls import include, url
from django.contrib import admin
from main.views import leaflet
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^/', include('main.urls', namespace='Home')),
url(r'^test/', leaflet.as_view()),
]
答案 1 :(得分:-1)
您urls.py
应该看起来像
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^/', include('main.urls'), name='Home'),
]
更新:
如果您使用的是django-1.8或更早版本,则应在app_name
函数中添加include
参数
url(r'^/', include('main.urls', namespace='Home', app_name='polls'))