Commit 90aa34ed authored by Давид Ли's avatar Давид Ли

lesson 45

parent a9f2ce94
......@@ -21,7 +21,9 @@ from web import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index_view),
path('', views.index_view, name='main-page'),
path('articles/add/', views.article_create_view, name='articles-add'),
# /articles/1/ OR /articles/?id=1
# article_details_view(request, id)
path('articles/<int:id>/', views.article_detail_view, name='articles-detail'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
No preview for this file type
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{% extends 'base.html' %}
<h1>Article</h1>
{% block title %}
<h1>Article checkout</h1>
{% endblock %}
{% block content %}
<h2>{{ article.title }}</h2>
<p>{{ article.text }}</p>
......@@ -15,5 +13,4 @@
<h4>Created: {{ article.created_at }}</h4>
<h4>Updated: {{ article.updated_at }}</h4>
</body>
</html>
\ No newline at end of file
{% endblock %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create</title>
</head>
<body>
{% extends 'base.html' %}
<h1>Create Article</h1>
<form action="/articles/add/" method="post">
{% csrf_token %}
<label>Title:</label><br/>
<input type="text" name="title"/><br/>
<label>Text:</label><br/>
<textarea name="text"></textarea><br/>
<label>Author:</label><br/>
<input type="text" name="author"/><br/>
{% block title %}
<h1>Create Article</h1>
{% endblock %}
<br/>
<input type="submit" value="Send"/>
</form>
</body>
</html>
{% block content %}
<form action="/articles/add/" method="post">
{% csrf_token %}
<div class="mb-3">
<label for="titleId" class="form-label">Title</label>
<input type="text" name="title" class="form-control" id="titleId" aria-describedby="title">
</div>
<div class="mb-3">
<label for="textId" class="form-label">Text</label>
<textarea name="text" class="form-control" id="textId" cols="30" rows="10"></textarea>
</div>
<div class="mb-3">
<label for="authorId" class="form-label">Author</label>
<input type="text" name="author" class="form-control" id="authorId" aria-describedby="author">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
{% endblock %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.1/css/bootstrap.min.css"
integrity="sha512-Ez0cGzNzHR1tYAv56860NLspgUGuQw16GiOOp/I2LuTmpSK9xDXlgJz3XN4cnpXWDmkNBKXR/VDMTCnAaEooxA=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
<title>Title</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="{% url 'main-page' %}">Articles</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse flex-grow-0" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="{% url 'articles-add' %}">
Create
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
{% block title %}{% endblock %}
{% block content %}{% endblock %}
</div>
{% block script %}{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.1/css/bootstrap.min.css" integrity="sha512-Ez0cGzNzHR1tYAv56860NLspgUGuQw16GiOOp/I2LuTmpSK9xDXlgJz3XN4cnpXWDmkNBKXR/VDMTCnAaEooxA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<title>Hello</title>
</head>
<body>
<div class="container">
<h1>Articles</h1>
<a href="{% url 'articles-add' %}" class="btn btn-primary">Создать</a>
{% for article in articles %}
{% block content %}
<h1>Articles</h1>
<a href="{% url 'articles-add' %}" class="btn btn-primary">Создать</a>
{% for article in articles %}
<br>
<hr>
<br>
......@@ -28,7 +18,5 @@
<br>
<hr>
<br>
{% endfor %}
</div>
</body>
</html>
\ No newline at end of file
{% endfor %}
{% endblock %}
\ No newline at end of file
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse
from web.models import Article
......@@ -6,7 +7,8 @@ from web.models import Article
def index_view(request):
return render(
request, 'index.html', context={
'articles': Article.objects.order_by('title')
'articles': Article.objects.order_by('title'),
'reverse': reverse('articles-detail', kwargs={'id': 1})
}
)
......@@ -30,5 +32,5 @@ def article_create_view(request):
# /articles/{id}
def article_detail_view(request, id: int):
article = Article.objects.get(id=id)
article = get_object_or_404(Article, id=id)
return render(request, 'article.html', context={'article': article})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment