Django is a beginner who develops web apps while studying.
I'm creating a page where I type in the search criteria for travel sites, but when I try to create a form and reflect it in the template, I can't pull the template as well as the image below.
I tried and tried to fix the problem, but it didn't improve.
I would appreciate it if someone could teach mem(__)m
from django import forms
class ConditionForm (forms.Form):
# start = 'Fixed'
goal=forms.CharField(label='Destination', max_length=30, required=True,)
people=forms.ChoiceField(label='number of people', choices=PEOPLE,
widget=forms.Select, required=True,
help_text='*Required',)
age=forms.CharField(label='age', required=True,
help_text='*Required',)
sex=forms.ChoiceField(label='gender', choices=SEX,
widget=forms.Select, required=True,
help_text='*Required',)
def clean_people():
cleaned_data=super().clean_people()
people = cleaned_data.get('people')
if not people:
raise forms.ValidationError('Please enter.')
return cleaned_data
defclean_age():
cleaned_data=super().clean_age()
people = cleaned_data.get('age')
if not age:
raise forms.ValidationError('Please enter.')
return cleaned_data
defclean_sex():
cleaned_data=super().clean_sex()
sex = cleaned_data.get('sex')
if not Sex:
raise forms.ValidationError('Please enter.')
return cleaned_data
from django.shortcuts import render, redirect
from django.http.response import HttpResponse
from.import forms
from django.template.response import TemplateResponse
from.forms import ConditionForm
def index(request):
return TemplateResponse(request, 'travel/condition.html',
{'index':index},)
condition_form(request):
form = ConditionForm (request.POST)
if request.method == 'POST':
if form.is_valid():
form.save()
context = {'form':form}
return render(request, 'travel/condition.html', context)
<!DOCTYPE html>
<html>
<head>
<title>
{{ index}}<br>
</title>
</head>
<body>
<form action='/form/'method='POST'>
{% csrf_token%}
{{ form.as_p}}<br>
<input type="submit" value="send">
</form>
</body>
</html>
def index(request):
form = ConditionForm()
return TemplateResponse(request, 'travel/condition.html', {'index':index', 'form':form})
Wouldn't it be necessary to pass the form
as context to the return
of the index
method?
The current output page appears to be the result returned by the index
method instead of condition_form
.
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
911 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
581 PHP ssh2_scp_send fails to send files as intended
578 Understanding How to Configure Google API Key
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.