Laurits L. L.
Laurits L. L.

Reputation: 417

Django - Nothing happens when "submit" button is clicked in a ModelForm?

Ok, so I am making a project, where you can make new blogposts and edit existing blogposts in Python with Django, but when I want to make a new post on my website, the "submit" button in new_post.html does nothing when I press it. I fill in the 'title' field and I fill in the 'text' field from the ModelForm "BlogPostForm" and press the button. In the terminal there's no POST or GET request. I just don't know why? I'm using Python 3.6.4 and Django 2.1, installed in a virtual environment created by the "venv" module.

base.html:

<p>
  <a href="{% url 'blogs:index' %}">Blogs</a>
</p>

{% block content %}{% endblock content %}

index.html:

{% extends "blogs/base.html" %}

{% block content %}

  <p>All posts:</p>

  <ul>
    {% for blog in blogs %}
      <li>
        {{ blog }}
        <p>{{ blog.date_added|date:'M D, Y H:i' }}</p>
        <p>{{ blog.text|linebreaks }}</p>
        <p>-------------------------------------<p>
      </li>
    {% empty %}
      <li>No posts are posted yet.</li>
      <p>
        <a href="{% url 'blogs:new_post' %}">Add new post</a>
      </p>
    {% endfor %}
  </ul>

  <p>
    <a href="{% url 'blogs:new_post' %}">Add new post</a>
  </p>

{% endblock content %}

new_post.html:

{% extends "blogs/base.html" %}

{% block content %}

  <p>Make a new post:</p>

  <post action="{% url 'blogs:new_post' %}" method='post'>
    {% csrf_token %}
    {{ post.as_p }}
    <button name='submit'>Add Post</button>
  </post>

{% endblock content %}

Thanks in advance!

Upvotes: 4

Views: 528

Answers (1)

OMY
OMY

Reputation: 412

There is no <post> tag in HTML. To post a data you need to use a <form> tag. Everything else is correct.

Upvotes: 1

Related Questions