Liondancer
Liondancer

Reputation: 16469

form not being loaded into template

I am trying to implement my form in Django but it is not appearing. I checked the inspector on my browser and I do not see it at all meaning it is not being loaded.

If there is any other information needed. Let me know.

project structure:

/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/templates/index/index.html:

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

{% block content %}


{% endblock %}

index/views.py

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

templates/home/home.html

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

{% block content %}{% endblock %}

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

I tried using {% blocks %} but then my navbar does not appear anymore. It only appears when I use 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>

Upvotes: 0

Views: 59

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599788

Your form is entirely within the navbar block, but you've commented that out in your home template. So nothing in that block will appear.

Upvotes: 1

Related Questions