H
H
howuu2018-08-15 06:07:16
Django
howuu, 2018-08-15 06:07:16

Form output in Django?

Made a shape

from django import forms

from .models import Post

class PostForm(forms.ModelForm):

    class Meta:
        model = Post
        fields = ('title', 'text',)

I take out
<h1>Новий пост</h1>
    <form method="POST" class="post-form">{% csrf_token %}
        {{ form.as_p }}
        <button type="submit" class="save btn btn-default">Save</button>
    </form>

Everything is fine, I just want to display it in such a layout
<div class="col-md-12 col-lg-8 main-content">
            <form method="POST">{% csrf_token %}
                  <div class="row">
                    <div class="col-md-4 form-group">
                      <label for="name">Заголовок</label>
                      <input type="text" id="name" class="form-control " >
                      
                    </div>
                    
                  </div>
                  <div class="row">
                    <div class="col-md-12 form-group">
                      <label for="message">Текст</label>
                      <textarea name="message" id="message" class="form-control " cols="30" rows="8"></textarea>
                      
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-6 form-group">
                      <input type="submit" value="Опубликовать" class="btn btn-primary">
                    </div>
                  </div>
                </form>
</div>

Essence of the question: Where to insert {{form.text}} and {{form.title}} so that the form works as it should and is displayed with html code as I want?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2018-08-15
@deliro

Or you can use https://github.com/jazzband/django-widget-tweaks
and don't mix python code with css and html.

E
Eugene, 2018-08-15
@immaculate

You need to use: django-crispy-forms .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question