E
E
Egoraccountmail2018-04-04 09:15:47
Django
Egoraccountmail, 2018-04-04 09:15:47

How to display the correct form in Djnago?

I use Ckeditor, for what reason is the site not displaying a beautiful form for editing, but the usual one is displayed?
Here is the model:

class Article(models.Model):
    user = models.ForeignKey(User)
    title = models.CharField(max_length=100)
    text = RichTextField()
    #moderation_journalist = models.BooleanField(default=False)
    moderation_editor = models.BooleanField(default=False)
    create_data = models.DateTimeField(auto_now_add=True)
    update_data = models.DateTimeField(auto_now=True)


    def __str__(self):
        return self.title

The form:
class ArticleForm(forms.ModelForm):
    class Meta:
        model = Article
        fields = (
            'title',
            'text',
        )

Weight:
def create_article(request):
    if request.POST:
        form = ArticleForm(request.POST)
        new = form.save(commit=False)
        new.user = request.user
        new.moderation_editor = False
        new.save()

        return redirect('/account/editor/')

    form = ArticleForm()
    args = {
        'form': form
    }

    return render(request, "accounts/create_article.html", args)

HTML:
<div class="container">

        <h1>Создайте новую запись:</h1>
        <br>
        <form enctype="multipart/form-data" method="post">
            {% csrf_token %}
            <p>{{ form.title }}</p>
            <p>{{ form.text }}</p>
        <button type="submit">Отправить</button>
    </form>
    </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-04-04
@Egoraccountmail

Nobody reads the documentation. First, be sure to complete python manage.py collectstatic. Secondly,

<div class="container">
    <h1>Создайте новую запись:</h1>
    <br>
    <form enctype="multipart/form-data" method="post">
        {{ form.media }}
        {% csrf_token %}
        <p>{{ form.title }}</p>
        <p>{{ form.text }}</p>
        <button type="submit">Отправить</button>
</form>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question