views.py
from django.shortcuts import render
from .models import Articles
from .forms import ArticlesForm
def news_home(request):
news = Articles.objects.order_by('-date')
return render(request, 'news/news_home.html', {'news': news})
def create(request):
form = ArticlesForm()
data = {
'form': form
}
return render(request, 'news/create.html', data)
forms.py
from .models import Articles
from django.forms import ModelForm
class ArticlesForm(ModelForm):
class Meta:
model = Articles
fields = ['title', 'anons', 'full_text', 'date']
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.news_home, name='news_home'),
path('create', views.create, name='create')
]