2015-04-29 63 views
0

我想在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/templates/navbar/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> 
+0

爲什麼你在home.html中註釋掉塊navbar? –

+0

您的'navbar.html'模板中的代碼是否完整,或者您是否可以將其從'home.html'擴展? – sthzg

+0

@sthzg我沒有從'home.html'中擴展它 – Liondancer

回答

1

您的表單完全位於navbar塊內,但您已在您的家庭模板中評論過。因此,該塊中沒有任何內容會出現。

+0

現在您已編輯了該問題以使我的答案無效。請不要這樣做。 –

+0

我再次更新了問題。對於那個很抱歉 – Liondancer