Lesson 37-2

parent b9755297
from django.urls import path from django.urls import path
from article.views import article_create_view from article.views import article_create_view, article_list_view
urlpatterns = [ urlpatterns = [
path('add/', article_create_view, name='add_article') path('add/', article_create_view, name='add_article'),
path('list/', article_list_view, name='article_list')
] ]
\ No newline at end of file
...@@ -19,4 +19,11 @@ def article_create_view(request): ...@@ -19,4 +19,11 @@ def article_create_view(request):
articles_list = Article.objects.all() articles_list = Article.objects.all()
return render(request, 'article/list.html', context={ return render(request, 'article/list.html', context={
'articles': articles_list 'articles': articles_list
}) })
\ No newline at end of file
def article_list_view(request):
articles_list = Article.objects.all()
return render(request, 'article/list.html', context={
'articles': articles_list
})
\ No newline at end of file
...@@ -121,6 +121,10 @@ USE_TZ = True ...@@ -121,6 +121,10 @@ USE_TZ = True
STATIC_URL = '/static/' STATIC_URL = '/static/'
# STATICFILES_DIRS = [
# [BASE_DIR / "static"]
# ]
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
......
<!doctype html> {% extends 'base.html' %}
<html lang="en">
<head> {% block content %}
<meta charset="UTF-8"> <div class="row">
<meta name="viewport" <div class="col-md-6">
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <form action="{% url 'add_article' %}" method="post">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> {% csrf_token %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"> <div class="mb-3">
<title>Document</title> <label for="title_input" class="form-label">Title</label>
</head> <input type="text" name="title" class="form-control" id="title_input" placeholder="Название...">
<body> </div>
<div class="container"> <div class="mb-3">
<div class="row"> <label for="content_input" class="form-label">Content</label>
<div class="col-md-6"> <textarea name="content" class="form-control" id="content_input" placeholder="Текст..."></textarea>
<form action="{% url 'add_article' %}" method="post"> </div>
{% csrf_token %} <div class="mb-3">
<div class="mb-3"> <label for="author_input" class="form-label">Author</label>
<label for="title_input" class="form-label">Title</label> <input type="text" name="author" class="form-control" id="author_input" placeholder="Автор...">
<input type="text" name="title" class="form-control" id="title_input" placeholder="Название..."> </div>
</div> <button type="submit" class="btn btn-success">Create</button>
<div class="mb-3"> </form>
<label for="content_input" class="form-label">Content</label>
<textarea name="content" class="form-control" id="content_input" placeholder="Текст..."></textarea>
</div>
<div class="mb-3">
<label for="author_input" class="form-label">Author</label>
<input type="text" name="author" class="form-control" id="author_input" placeholder="Автор...">
</div>
<button type="submit" class="btn btn-success">Create</button>
</form>
</div>
</div> </div>
</div> </div>
</body> {% endblock %}
</html> \ No newline at end of file
\ No newline at end of file
<!doctype html> {% extends 'base.html' %}
<html lang="en">
<head> {% block content %}
<meta charset="UTF-8"> <h4>{{ message }}</h4>
<meta name="viewport" <div class="row">
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <div class="col-md-6">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <h2>Статья</h2>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"> <p>{{ article.title }}</p>
<title>Document</title> <p>{{ article.author }}</p>
</head> <p>{{ article.content }}</p>
<body>
<div class="container">
<h4>{{ message }}</h4>
<div class="row">
<div class="col-md-6">
<h2>Статья</h2>
<p>{{ article.title }}</p>
<p>{{ article.author }}</p>
<p>{{ article.content }}</p>
</div>
</div> </div>
</div> </div>
</body> {% endblock %}
</html> \ No newline at end of file
\ No newline at end of file
<!doctype html> {% extends 'base.html' %}
<html lang="en">
<head> {% block content %}
<meta charset="UTF-8"> <div class="row">
<meta name="viewport" <div class="col-md-6">
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <ul>
<meta http-equiv="X-UA-Compatible" content="ie=edge"> {% for article in articles %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"> <li>{{ article }}</li>
<title>Document</title> {% endfor %}
</head> </ul>
<body>
<div class="container">
<div class="row">
<div class="col-md-6">
<ul>
{% for article in articles %}
<li>{{ article }}</li>
{% endfor %}
</ul>
</div>
</div>
</div> </div>
</body> </div>
</html> {% endblock %}
\ No newline at end of file
{#{% 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 href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
{# <link rel="stylesheet" href="{% url 'css/style.css' %}">#}
<title>Document</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</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" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</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>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
{% block content %}
{% endblock %}
</div>
</body>
</html>
\ No newline at end of file
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