I am writing an application with django. I know how to implement the django forms but what I want to do really is to have an html input input with type text or email or password and save the input to database or link it to the form.py
form.py
class PostForm(forms.ModelForm):
publish = forms.DateField(widget= forms.SelectDateWidget)
class Meta:
model = Post
fields = [
"title",
"content",
]
views.py
def create(request):
form = PostForm(request.POST or None, request.FILES or None)
if form.is_valid():
instance = form.save(commit=False)
instance.save()
messages.success(request, "Post created")
return HttpResponseRedirect(instance.get_absolute_url())
context = {
"form": form,
}
template = 'create.html'
return render(request,template,context)
html
<form method="POST" action="" enctype="multipart/form-data">{% csrf_token %}
{{ form.as_p }}
<p>
<input type="checkbox" id="test5" />
<label for="test5">Red</label>
</p>
<input type="submit" name="submit" value="submit post">
</form>
request.POST.get('test5')I dont understand the question maybe{{ form.as_p }}with individual html input tags?