Commit 7c041a43 authored by Давид Ли's avatar Давид Ли

lesson 42

parent c4ddd62e
...@@ -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
......
...@@ -21,4 +21,5 @@ from webapp import views ...@@ -21,4 +21,5 @@ from webapp import views
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('123', views.index_view), path('123', views.index_view),
path('articles/add', views.article_create_view)
] ]
This source diff could not be displayed because it is too large. You can view the blob instead.
body {
font-family: Arial, sans-serif;
margin: 0;
background-color: aqua;
}
.container {
margin: 0 auto;
width: 80%;
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<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>
<br>
<input type="submit" value="Send">
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>New Article</h1>
<h2>{{ title }}</h2>
<p>{{ text }}</p>
<p>By: {{ author }}</p>
</body>
</html>
\ No newline at end of file
{% load static %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static "css/styles.css" %}">
<link rel="stylesheet" href="{% static "css/bootstrap.min.css" %}">
<title>Document</title> <title>Document</title>
<style>
* {
margin: 0;
}
.container {
margin: 0 auto;
width: 80%;
text-align: center;
}
</style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>This is my first Django project!</h1> <h1>This is my first Django project!</h1>
<button class="btn btn-success">bootstrap connected</button>
<img src="{% static "img/spider_men.jpg" %}" alt="">
</div> </div>
</body> </body>
......
...@@ -4,6 +4,32 @@ from django.shortcuts import render ...@@ -4,6 +4,32 @@ from django.shortcuts import render
# MVC - Model View Controller # MVC - Model View Controller
# MTV - Model Template View # MTV - Model Template View
# <QueryDict: {'hello': ['world1', 'world2']}>
# GET - получение http://localhost:1027/123?hello=world
# http://localhost:1027/123?hello=world1&hello=world2
# POST - действие
def index_view(request): def index_view(request):
return render(request, 'index.html') return render(request, 'index.html')
# <QueryDict: {'csrfmiddlewaretoken': ['NSGuE2NGozjOQoH6d8d7CsBvW8jTmF57Hjbooz6VMoXTEIQkEynKqyeqiddle6e3'],
# 'title': ['article 1'], 'text': ['rewgsdgadgdsagdsagsdag'],
# 'author': ['anonymous author']}>
def article_create_view(request):
if request.method == 'GET':
return render(request, 'articles/create.html')
elif request.method == 'POST':
print(request.POST)
context = {
'title': request.POST.get('title'),
'text': request.POST.get('text'),
'author': request.POST.get('author'),
}
return render(request, 'articles/detail.html', context)
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