如果我使用template_name变量,我的SessionWizardView就像pycharm一样工作!
我遇到了SessionWizardView提供的get_template_names()方法的麻烦。
我使用get_template_names()方法的第一个模板呈现完美显示正确的url。
http://127.0.0.1:8000/wow/character_creation/
我提交表单,我的第二个表单使用get_template_name()方法呈现完美显示正确的网址和表单。
http://127.0.0.1:8000/wow/character_creation/
我提交了我的第二张表格,或者如果我按上一步或第一步,则会显示以下网址
http://127.0.0.1:8000/character_creation/
以下是错误消息:
Page not found (404)
Request Method: POST
Request URL: http://127.0.0.1:8000/character_creation/
在提交第二张表格时,是否有人知道我的网址/ wow /部分被删除了? get_template_names()方法中有错误吗?
这是我的views.py
FORMS = [
("0", wow.forms.CharacterCreationForm1),
("1", wow.forms.CharacterCreationForm2),
("2", wow.forms.CharacterCreationForm3),
TEMPLATES = {
"0": "wow/character_creation_form_1.html",
"1": "wow/character_creation_form_2.html",
"2": "wow/character_creation_form_3.html",
}
class CharacterWizard(SessionWizardView):
instance = None
#template_name = "wow/character_creation_form_1.html"
# Requires the user to be logged in for every instance of the form wizard
# as-view() *urls.py* creates an instance called dispatch(). Dispatch is used to relay information
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
self.instance = CharacterCreation()
return super(CharacterWizard, self).dispatch(request, *args, **kwargs)
def get_form_instance(self, step):
return self.instance
def get_template_names(self):
#Custom templates for the different steps
return [TEMPLATES[self.steps.current]]
def done(self, form_list, **kwargs):
self.instance.character_creation_user = self.request.user
self.instance.save()
return HttpResponseRedirect('/wow/home/')
这是我的url.py
url(r'^ character_creation / $',CharacterWizard.as_view(FORMS),name ='character_creation'),
谢谢你们!
答案 0 :(得分:0)
在我的第二个和第三个模板中,我的表单现在是action="/character_creation/"
而不是/wow/character_creation/
。