Search code examples
djangodjango-viewsdjango-forms

Submit button has no action in Django


I have 3 models in my project and no form is showing any action when the submit button is pressed after putting all the inputs of the form.
forms.py

class BlogForm(forms.ModelForm):
    class Meta:
        model = BlogPost
        fields = ['title', 'slug', 'thumbnail', 'body', 'status', 'is_subsriber', 'meta', 'author']

models.py

class BlogPost(models.Model):
    author = models.ForeignKey(Author, on_delete = models.CASCADE)
    title = models.CharField(max_length = 999, unique = True)
    slug = models.SlugField(max_length = 999, unique = True)
    thumbnail = ProcessedImageField(upload_to='article', format='JPEG', options={'quality': 60})
    body = CKEditor5Field(config_name='extends')
    meta = models.TextField()
    status = models.CharField(max_length = 10, choices = blogstatus, default = "DF")
    is_subsriber = models.BooleanField(default = False)
    created_on = models.DateTimeField(auto_now_add = True)
    published_on = models.DateField(auto_now = True)
    modified_on = models.DateField(auto_now = True)

views.py

def article_form(request):
    if request.method == "POST":
        form = BlogForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect("home")
    else:
        form = BlogForm()
    return render(request, 'article/post-form.html', {"form":form})

index.html

<form class="form" method="post">
                        {% csrf_token %}
                        {{form.as_p}}
                        <button type="submit">Publish</button>
                    </form>


This is just one model and its form. I've tried using action in the html form but it still doesn't work.

Solution

  • This was due to django-ckeditor5 package that I've installed. This works well using the django admin but it doesn't work when used in forms.