Display not populating for all fields from entry

Greetings!!

I have a submit/display function that is not displaying all the values after fields have been sent through. Any help would be greatly appreciated.

my submit form:

{% extends "CMS/base.html" %}
{% block content %}
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
	<form method ='POST'>
		{% csrf_token %} <!-- prevent faking the form-->
		{{ form.as_p }}      <!-- #display the form-->
		<input type ="submit" value="submit user"/>
	</form>
</body>
</html>
{% endblock content %}

my model:

class Casa(models.Model):
    Student = models.CharField(max_length=25,blank=False)
    Cohort  = models.CharField(max_length=44,blank=False)
    Phone_Number = models.CharField(max_length=15,blank=False)
    Email_Address = models.CharField(max_length=44,blank=False)
    Home_Address = models.CharField(max_length=44,blank=False)
    City = models.CharField(max_length=25,blank=False)
    State = models.CharField(max_length=3,blank=False)
    Zip_Code = models.CharField(max_length=10,blank=False)
    def __str__(self):
        return self.title 
    def get_absolute_url(self):
        return reverse('entry',kwargs={'pk': self.pk})

potentially important base page

{% extends "CMS/base.html" %}
{% block content %}
<section>
	<section class="row">
		<div class="col-md-4">
			<strong>First/Last Name</strong>
		</div>
		<div class="col-md-10">
			{{ casa.student }}
		</div>
			</strong>
	</section>
	<section class="row">
		<div class="col-md-4">
			<strong>Cohort</strong>
		</div>
		<div class="col-md-10">
			{{ casa.cohort }}
		</div>
			</strong>
	</section>
	<section class="row">
		<div class="col-md-4">
			<strong>Phone Number</strong>
		</div>
		<div class="col-md-10">
			{{ casa.phone_number }}
		</div>
			</strong>
	</section>	
	<section class="row">
		<div class="col-md-4">
			<strong>Home Address</strong>
		</div>
		<div class="col-md-10">
			{{ casa.home_address }}
		</div>
			</strong>
	</section>	
	<section class="row">
		<div class="col-md-4">
			<strong>Email Address</strong>
		</div>
		<div class="col-md-10">
			{{ casa.email_address }}
		</div>
			</strong>
	</section>	
		<section class="row">
		<div class="col-md-4">
			<strong>State</strong>
		</div>
		<div class="col-md-10">
			{{ casa.state }}
		</div>
			</strong>
	</section>
	<section class="row">
		<div class="col-md-4">
			<strong>Zip_Code</strong>
		</div>
		<div class="col-md-10">
			{{ casa.zip_code }}
		</div>
			</strong>
	</section>	
</section>
{% endblock content%}


kind regards,

BMT

What about the Views? Something is producing the Forms too, right? What’s that?

from django.shortcuts import render,HttpResponse
from . import models
from . models import Post, Casa
from django.views.generic import ListView,DetailView,CreateView  
from django.core.paginator import Paginator

# Created views here.
def home(request):
    context = {
        'posts' : Post.objects.all()
    }
    return render(request,'CMS/home.html',context)

def about(request):
    return render(request,'CMS/about.html',{'title': 'About'})

def HHAProg(request):
    return render(request,'CMS/HHAProg.html',{'title': 'HHAProg'})

class IndexView(ListView):
    context_object_name ='casa'
    template_name = 'CMS/home.html'

    def get_queryset(self):
        return models.Casa.objects.all()

class DetailView(DetailView):
    context_object_name ='casa'
    model=models.Casa
    template_name = 'CMS/entry.html'

class CreateView(CreateView):
  model= models.Casa 
  fields = ['Student','Cohort','Phone_Number','Email_Address','Home_Address','City','State','Zip_Code']
  template_name ='CMS/edit.html'

I’m having problems figuring out what the issue is from the information presented so far.

You wrote:

I’m understanding this to mean that you’re looking at a page containing a form created by a view.

  • Is my understanding correct?
  • What is that URL?
  • What is the name of the view?
  • What is the form? (I do not see a form definition in what you posted.)

You then submit that form, it should direct you to a different page.

  • What is the url for the page you are being directed to?
  • What is the view that is supposed to generate that page being rendered?
  • What url are you actually being directed to?
  • What does your urls.py file look like for this app?

Ken!

Your inability to understand my question is due to my inability to appropriately describe my problem. Agreed/My apologies.

I am trying to set up a page that takes entries and populates user information on the database. Currently, when navigating to http://localhost:8000/submit, a form that uses the model “Casa” populates a series of entries. When I submit the form it goes to this website, localhost:8000/13, but nothing comes up that displayed information. Every time I submit, localhost:8000/X the /X increases by one, but the information is always the same.

local host/submit


Student: [input parameters]

Cohort: [input parameters]

Phone Number: [user input parameters]

Email Address: [user input parameters]

Home Address: [user input parameters]

City: [user input parameters]

State: [user input parameters]

Zip Code:  [user input parameters]

[submit button]


display page ,
http://localhost:8000/13,


First/Last Name          [blank fields]
Cohort                        [blank fields]
Phone Number           [blank fields]
Home Address           [blank fields]
Email Address            [blank fields]
State                           [blank fields]
Zip_Code                   [blank fields]  
 

8000/submit

This is “edit.html” page:

{% extends "CMS/base.html" %}
{% block content %}
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
	<form method ='POST'>
		{% csrf_token %} <!-- prevent faking the form-->
		{{ form.as_p }}      <!-- #display the form-->
		<input type ="submit" value="submit user"/>
	</form>
</body>
</html>
{% endblock content %}

This is the page for the information bout the entries “entry.html”.

8000/X
where x is the number of submissions

{% extends "CMS/base.html" %}
{% block content %}
<section>
	<section class="row">
		<div class="col-md-4">
			<strong>First/Last Name</strong>
		</div>
		<div class="col-md-10">
			{{ casa.student }}
		</div>
			</strong>
	</section>
	<section class="row">
		<div class="col-md-4">
			<strong>Cohort</strong>
		</div>
		<div class="col-md-10">
			{{ casa.cohort }}
		</div>
			</strong>
	</section>
	<section class="row">
		<div class="col-md-4">
			<strong>Phone Number</strong>
		</div>
		<div class="col-md-10">
			{{ casa.phone_number }}
		</div>
			</strong>
	</section>	
	<section class="row">
		<div class="col-md-4">
			<strong>Home Address</strong>
		</div>
		<div class="col-md-10">
			{{ casa.home_address }}
		</div>
			</strong>
	</section>	
	<section class="row">
		<div class="col-md-4">
			<strong>Email Address</strong>
		</div>
		<div class="col-md-10">
			{{ casa.email_address }}
		</div>
			</strong>
	</section>	
		<section class="row">
		<div class="col-md-4">
			<strong>State</strong>
		</div>
		<div class="col-md-10">
			{{ casa.state }}
		</div>
			</strong>
	</section>
	<section class="row">
		<div class="col-md-4">
			<strong>Zip_Code</strong>
		</div>
		<div class="col-md-10">
			{{ casa.zip_code }}
		</div>
			</strong>
	</section>	
</section>
{% endblock content%}

my views/URL patturns

from django.shortcuts import render,HttpResponse
from . import models
from . models import Post, Casa
from django.views.generic import ListView,DetailView,CreateView  
from django.core.paginator import Paginator

# Created views here.
def home(request):
    context = {
        'posts' : Post.objects.all()
    }
    return render(request,'CMS/home.html',context)

def about(request):
    return render(request,'CMS/about.html',{'title': 'About'})

def HHAProg(request):
    return render(request,'CMS/HHAProg.html',{'title': 'HHAProg'})

class IndexView(ListView):
    context_object_name ='casa'
    template_name = 'CMS/home.html'

    def get_queryset(self):
        return models.Casa.objects.all()

class DetailView(DetailView):
    context_object_name ='casa'
    model=models.Casa
    template_name = 'CMS/entry.html'

class CreateView(CreateView):
  model= models.Casa 
  fields = ['Student','Cohort','Phone_Number','Email_Address','Home_Address','City','State','Zip_Code']
  template_name ='CMS/edit.html'

from django.urls import path
from . import views 
from django.contrib.auth import views as auth_views

urlpatterns = [
        path('',views.home,name='CMS-home'),
        path('about/',views.about,name='CMS-about'),
        path('HHAProg/',views.HHAProg,name='CMS-HHAProg'),
        path('<int:pk>', views.DetailView.as_view(),name='entry'),
        path('submit',views.CreateView.as_view(),name='submit')
]


No apologies required - this is a conversation. You ask questions, I ask questions. You answer questions, I answer questions. Generally tends to work out.

Anyway, you have defined your fields as follows:

(Side note: These names are contrary to the generally recommended Python coding conventions as detailed in PEP 8. Classes are capitalized while attributes and methods are lower-case.)

However, your template refers to them like this:

{{ casa.student }}
{{ casa.cohort }}
{{ casa.phone_number }}
{{ casa.home_address }}
{{ casa.email_address }}
{{ casa.state }}
{{ casa.zip_code }}

They are not the same.

Variable names in Python are case sensitive.