Crispy form is not rendring

Trying to render the form but it renders without crispy tags.

I have done

  • installed django-crispy-forms (using pip)
  • added 'CRISPY_TEMPLATE_PACK' to my settings
  • added 'crispy_forms' to my applications
  • load the crispy tag to register.html (using {% load crispy_forms_tags %})

How it render

forms.py
---------
      from django import forms
        class helomodel(forms.Form):
            name = forms.CharField()
            email = forms.EmailField()
            content = forms.CharField()

    views.py 
    ---------
    from django.shortcuts import render
    from . forms import helomodel
    
    def register(response):
        form = helomodel()
        return render(response,'main/register.html',{'form':form})

    settings.py 
    -----------
    INSTALLED_APPS = [
        'main.apps.MainConfig',
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'crispy_forms',
    ]
    
    
    CRISPY_TEMPLATE_PACK = 'bootstrap4'

 

    Register.html 
    --------------
    {% extends 'main/base.html' %}
    {% load crispy_forms_tags %}
    
    {% block content %}
      <form method="post">
        {% csrf_token %}
        {{ form|crispy }}
    
        <button type="submit" class="btn btn-success">Register</button>
      </form>
    {% endblock %}



  • u r missing form.as_p() || form.as_table() || form.as_ul() after {{ form|crispy }}, which will output the form fields in a <p>, <table> or <ul> respectively

  • u r also missing or in the form here is an example of how u can do it

<button type="submit" class="btn btn-success">Register</button>
Back to Top