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
from django import forms
from .models import Project
class projectForm(forms.ModelForm):
class Meta:
model = Project
fields = [
'project_id',
]
Views.py
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
{% 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
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'projects’,
'crispy_forms',
]
Screenshot