表单未加载到模板中

时间:2015-04-29 15:51:10

标签: python html django

我正在尝试在Django中实现我的表单,但它没有出现。我在我的浏览器上检查了检查员,我根本没有看到它,这意味着它没有被加载。

如果还需要其他信息。让我知道。

项目结构:

/beerad
   urls.py
   /index
      views.py
      /templates
         /index
            index.html
   /templates
      /home
         home.html
      /navbar
         navbar.html
   /userapp
      forms.py
      views.py
      urls.py

userapp / forms.py:

class RegistrationFrom(forms.Form):
    username = forms.CharField(max_length=50, widget=forms.TextInput(attrs={"id": "signup-username", "name": "username", "placeholder": "Username"}))
    first_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs={"id": "signup-firstname", "name": "firstname", "placeholder": "First Name"}))
    last_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs={"id": "signup-lastname", "name": "lastname", "placeholder": "Last Name"}))
    email = forms.EmailField(max_length=50, widget=forms.EmailInput(attrs={"id": "signup-email", "name": "email", "placeholder": "Email"}))
    password = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={"id": "signup-password", "name": "password", "placeholder": "Password"}))
    confirm_password = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={"id": "signup-confirm-password", "name": "confirm-password", "placeholder": "Confirm Password"}))

索引/模板/索引/ index.html中:

{% extends "home/home.html" %}

{% block content %}


{% endblock %}

索引/ views.py

def load_index(request):
    if request.method == "GET":
        return render(request, "index/index.html")

模板/家/ home.html的

<body class="container">
{#{% block navbar %}{% endblock %}#}
{% include "navbar/navbar.html" %}

{% block content %}{% endblock %}

{% include "footer/footer.html" %}
{#{% block footer %}{% endblock %}#}
</body>

我尝试使用{% blocks %},但我的navbar不再出现了。它仅在我使用include

时出现
<body class="container">
{% include "navbar/navbar.html" %}

{% block content %}{% endblock %}

{% include "footer/footer.html" %}
</body>

beerad / urls.py:

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include("index.urls")),
    url(r'auth/', include("userapp.urls"))
)

userapp / urls.py

urlpatterns = patterns('',
    url(r'signup/$', register),
    url(r'activation/$', activation)
)

userapp / views.py:

def register(request):
    if request.method == "POST":
        form = RegistrationFrom(request.POST)
        if form.is_valid():
            return render(request, "success.html", {"payload": request.POST})
        else:
            return render(request, "error/404.html")
    else:
        form = RegistrationFrom()
    return render(request, "navbar/navbar.html", {"form": form})

beerad /模板/导航栏/ navbar.html:

    <div role="tabpanel" class="tab-pane fade in" id="signup-pane">
      <form class="signup-form" method="post" action="/auth/signup/" id="create-account">
        {% csrf_token %}
        {{ form }}
        <button type="submit"  class="btn btn-xl" id="create-acc-btn" name="signup-submit">Create Account</button>
      </form>
    </div>

1 个答案:

答案 0 :(得分:1)

您的表单完全在导航栏中,但您已在家庭模板中注释了该表单。因此,该区块中的任何内容都不会出现。