Answer the question
In order to leave comments, you need to log in
How to fix django file display?
When I started writing forms in create.html, the display of the page as an html document changed to the display of the document's code. please help
the views.py file
from django.shortcuts import render
from django.http import HttpResponse
from .models import hot, post
from .forms import postform
# Create your views here.
def index(request):
return render(request, 'main/index.html', {'title': 'О ПРОЕКТЕ'})
def me(request):
return render(request, 'main/me.html', {'title': 'Я'})
def news(request):
return render(request, 'main/news.html', {'hn': hot.objects.all(), 'sn':post.objects.order_by('-id'), 'title': 'НОВОСТИ'})
def create(request):
return render(request, 'main/create.html', {'title': 'Новый пост'}, {'form': postform()})
from .models import post
from django.forms import ModelForm, TextInput
class postform(ModelForm):
class Meta:
model = post
fields = ['title', 'text']
widgets = {
'title': TextInput(attrs={
'class': 'form-control',
'placeholder': 'Название'
}),
'text': TextInput(attrs={
'class': 'form-control',
'placeholder': 'Текст'
})
}
{% extends 'main/base.html' %}
{% block title %}{{ title }}{% endblock %}
{% block header %}
<a href="{% url 'feed' %}" class="first upnav"> НОВОСТИ </a>|
<a href="" class="upnav"> ОБЩЕНИЕ</a>
{% endblock %}
{% block body %}
<form method="post">
{% csrf_token %}
{{ form.title }}<br>
{{ form.text }}<br>
<button type="submit" class="btn btn-success">Добавить</button>
</form>
{% endblock %}
Answer the question
In order to leave comments, you need to log in
return render(request, 'main/create.html', {'title': 'Новый пост'}, {'form': postform()})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question