页面处理器无法正常工作

时间:2014-04-01 11:48:38

标签: python django mezzanine

processors.py文件:

from django import forms
from django.http import HttpResponseRedirect
from mezzanine.pages.page_processors import processor_for
from .models import Author

class AuthorForm(forms.Form):
    name = forms.CharField()
    email = forms.EmailField()

@processor_for(Author)
def author_form(request, page):
    form = AuthorForm()
    if request.method == "POST":
        form = AuthorForm(request.POST)
        if form.is_valid():
            # Form processing goes here.
            redirect = request.path + "?submitted=true"
            return HttpResponseRedirect(redirect)
    return {"form": form}

这里定义urls.py文件,我在其中定义处理器:

url("^xyz/$", "mezzanine.pages.views.page", {"slug": "Author"},  name="Author"),

表单仍然无法显示。我该如何解决这个错误?

1 个答案:

答案 0 :(得分:0)

错误:始终在"中定义处理器名称"比如@processor_for("作者")

   **@processor_for("Author")** 

    def author_form(request, page):
        form = AuthorForm()
        if request.method == "POST":
            form = AuthorForm(request.POST)
            if form.is_valid():
                # Form processing goes here.
                redirect = request.path + "?submitted=true"
                return HttpResponseRedirect(redirect)
        return {"form": form}