[Answered ]-Django form request post not loading data

1👍

You first should call form.is_valid() [Django-doc]:

from django.shortcuts import get_object_or_404

@login_required
def articleChangeView(request, pk):
    article = get_object_or_404(Article, pk=pk, author=request.user)
    if request.method == 'POST':
        form = forms.ArticleCreateForm(request.POST)
        if form.is_valid():
            print('--------')
            print(request.POST)
            print(form.cleaned_data)

The clean methods of your clean_fieldnames should also return the cleaned value, so:

class ArticleCreateForm(forms.Form):
    # …

    def clean_title(self):
        data = self.cleaned_data['title']
        if len(data) < 3:
            raise ValidationError('Title is too short')
        return data

    def clean_tagging(self):
        data = self.cleaned_data['tagging']
        if not data:
            raise ValidationError('Please add at least one tag')
        return data

Leave a comment