In my views.py my have a view where a user can create a post with a title, media file and caption.
When i check if form.is_valid():
it always returns as false and i cannot see the issue with my form.
views.py
def your_profile(request):
if request.method == "POST":
form = CreatePost(request.POST)
if form.is_valid():
title = form.cleaned_data.get("title_input")
media = form.cleaned_data.get("media_input")
caption = form.cleaned_data.get("caption_input")
context = {"title": "Your Profile"}
return render(request, "myApp/your_profile.html", context)
forms.py
class CreatePost(forms.Form):
title = forms.CharField(max_length=30)
media = forms.FileField(max_length=350)
caption =forms.CharField(max_length=300)
html
<form action="" method="post">
<input type="text" name="title_input" id="title_input">
<label for="title_input">Title</label>
<input type="file" name="media_input" id="media_input">
<label for="media_input">Media</label>
<input type="text" name="caption_input" id="caption_input">
<label for="caption_input">Caption</label>
<input type="submit" value="POST!">
</form>