# Django not rendering Crispy Form Fields from models.py

**URL:** https://forum.djangoproject.com/t/django-not-rendering-crispy-form-fields-from-models-py/3121
**Category:** Using Django
**Created:** [June 24, 2020, 11:33pm UTC](https://forum.djangoproject.com/t/django-not-rendering-crispy-form-fields-from-models-py/3121 "2020-06-24T23:33:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jamessemaj33](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jamessemaj33/32/1529_2.png) [@Jamessemaj33](https://forum.djangoproject.com/u/Jamessemaj33)
#### Post date: [June 24, 2020, 11:33pm UTC](https://forum.djangoproject.com/t/django-not-rendering-crispy-form-fields-from-models-py/3121/1 "2020-06-24T23:33:40Z")

</div>

Hi i’m new to Django and In my first project I am trying to construct a new project form to fill in information to store online. I’m using bootstrap4 as the default template pack with django\_crispy\_forms. I have been trying to render a form with the crispy tags/filter. I have created another form for enquires and had success in rendering the fields from forms.py. However this time I need to render the form from a model. The button and title render on the template but no matter what I try from other examples of modelforms I cant seem to make my fields render to the template like it should.

I have tried renaming the models.py field name, stripping the code back to just the basics,I have also tried starting a new django project with just projects and crispy forms as the only user installed apps. However I still get the same issue of only the button appearing with no form fields rendered from models.py. So I don’t believe it is bug related to other installed apps…I am a bit lost as what to try next…I have got form fields showing in another app based off information within the forms.py but trying to render form fields from the models.py information doesn’t seem to work. Getting information from the model is critical for the rest of my project to function. Does anyone have any suggestions of what to try next?

Any help would be greatly appreciated.

**Models.py**

```
from django.db import models

# Create your models here.
class Project(models.Model):
project_address = models.CharField(max_length=200, null=True)

```

**Forms.py**

```auto
from django import forms
from .models import Project

class projectForm(forms.ModelForm):
    class Meta:
        model = Project
        fields = [
            'project_id',
        ]

```

**Views.py**

```auto
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.conf import settings 

from .models import Project
from .forms import projectForm

def projectinfo(request):
    form = projectForm(request.POST or None)
    context = {}
    template = 'projectinfo.html'
    return render(request,template,context)

```

HTML

```auto
{% load crispy_forms_tags %}

{% block content %}

            <form action="{% url 'projectinfo' %}" method="POST">{% csrf_token %}
                {{ form|crispy }}               
                <input type="submit" value="Save Project" class="btn btn-default" role="button" style="background-color: #007bff; color: #ffffff;"/>
            </form>

{% endblock %}

```

Settings.py

```auto
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'projects’,
    'crispy_forms',

]

```

Screenshot

 ![Screen Shot 2020-06-25 at 9.31.05 am](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/d/d64fd6b07580964c69a40efee3d962f23e21cc1d.png)

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [June 24, 2020, 11:39pm UTC](https://forum.djangoproject.com/t/django-not-rendering-crispy-form-fields-from-models-py/3121/2 "2020-06-24T23:39:28Z")

</div>

In your forms file, the form name is ProjectForm but in views you’re using the name projectForm. I would expect this to cause your application to not run at all, so is this a copy/paste error?

---

<div class="post-metadata">

### Author: ![Jamessemaj33](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jamessemaj33/32/1529_2.png) [@Jamessemaj33](https://forum.djangoproject.com/u/Jamessemaj33)
#### Post date: [June 25, 2020, 12:22am UTC](https://forum.djangoproject.com/t/django-not-rendering-crispy-form-fields-from-models-py/3121/3 "2020-06-25T00:22:18Z")

</div>

Hi Ken, Thanks for your help, it was a typo sorry. I have updated the forms.py code above.

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [June 25, 2020, 2:03am UTC](https://forum.djangoproject.com/t/django-not-rendering-crispy-form-fields-from-models-py/3121/4 "2020-06-25T02:03:20Z")

</div>

You’re not including the form in your context to be rendered.

Your view:

```auto
def projectinfo(request):
    form = projectForm(request.POST or None)
    context = {}
    template = 'projectinfo.html'
    return render(request,template,context)

```

On line 2, you’re creating a form - but you’re not making part of your context on line 3.

You might find it helpful to review the [Django Forms documentation](https://docs.djangoproject.com/en/3.0/topics/forms/), particularly the section on [The view](https://docs.djangoproject.com/en/3.0/topics/forms/#the-view).

Ken

---

<div class="post-metadata">

### Author: ![Jamessemaj33](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jamessemaj33/32/1529_2.png) [@Jamessemaj33](https://forum.djangoproject.com/u/Jamessemaj33)
#### Post date: [June 25, 2020, 4:52am UTC](https://forum.djangoproject.com/t/django-not-rendering-crispy-form-fields-from-models-py/3121/5 "2020-06-25T04:52:16Z")

</div>

Thanks Ken, I have updated my view to:

```
def projectinfo(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
    # create a form instance and populate it with data from the request:
    form = projectForm(request.POST)
    # check whether it's valid:
    if form.is_valid():
        # process the data in form.cleaned_data as required
        # ...
        # redirect to a new URL:
        return HttpResponseRedirect('/Project Updated/')

# if a GET (or any other method) we'll create a blank form
else:
    form = projectForm()

return render(request, 'projectinfo.html', {'form': form})

```

and the form field has finally appeared in the template. Thanks so much for your help, it is greatly appreciated.
