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

completed lesson_42

parent 04f0bd74
...@@ -12,6 +12,7 @@ body { ...@@ -12,6 +12,7 @@ body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
font-size: 16px; font-size: 16px;
color: #444444; color: #444444;
background-color: pink;
} }
.container { .container {
......
...@@ -121,14 +121,14 @@ USE_TZ = True ...@@ -121,14 +121,14 @@ USE_TZ = True
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [ STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static') os.path.join(BASE_DIR, 'banana')
] ]
#
#
# Media files # # Media files
#
MEDIA_URL = '/media/' # MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# 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
......
...@@ -17,9 +17,10 @@ from django.conf import settings ...@@ -17,9 +17,10 @@ from django.conf import settings
from django.conf.urls.static import static from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from web.views import index_view from web import views
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', index_view) path('', views.index_view),
path('articles/add/', views.article_create_view)
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</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="content"></textarea><br/>
<label>Author:</label><br/>
<input type="text" name="author"/><br/>
<br/>
<input type="submit" value="Send"/>
</form>
{{ calculate_result }}
<h1>Future article:</h1>
<h2>{{ title }}</h2>
<p>{{ content }}</p>
<h5>By: {{ author }}</h5>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create</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="content"></textarea><br/>
<label>Author:</label><br/>
<input type="text" name="author"/><br/>
<br/>
<input type="submit" value="Send"/>
</form>
</body>
</html>
...@@ -15,26 +15,12 @@ ...@@ -15,26 +15,12 @@
<p>This is my first Django project!</p> <p>This is my first Django project!</p>
<h1>{{ greetings|default:"Hello World!" }}</h1> <h1>{{ greetings|default:"Hello World!" }}</h1>
{% lorem 5 random %} <form action="" method="post">
{% now "SHORT_DATETIME_FORMAT" %} {% csrf_token %}
<input type="text" name="name">
{% for product, price in products.items %} <input type="text" name="surname">
{% if forloop.first %} <input type="submit" value="Send">
<hr> </form>
{% elif not forloop.first %}
{% else %}
{% endif %}
<h2>{{ product }} - {{ price }}</h2>
{% if forloop.last %}
<hr>
{% endif %}
{% empty %}
<h1>There are no products :c</h1>
{% endfor %}
<p>Hello World!</p> <p>Hello World!</p>
</div> </div>
......
...@@ -2,13 +2,31 @@ from django.shortcuts import render ...@@ -2,13 +2,31 @@ from django.shortcuts import render
def index_view(request): def index_view(request):
if request.method == 'POST':
print(request.POST)
else:
print(request.GET)
print(request.GET.get('name'))
print(request.GET.getlist('name'))
return render( return render(
request, 'index.html', context={ request, 'index.html', context={
'greetings': 'Hello AP-11!' 'greetings': 'Hello AP-11!'
# 'products': {
# 'Banana': 120,
# 'Apple': 100,
# 'Bread': 70
# }
} }
) )
def article_create_view(request):
context = {}
if request.method == 'GET':
print(request.GET.get('name'))
# return render(request, 'article_create.html')
elif request.method == 'POST':
print(request.POST)
data = request.POST
context = {
'title': data.get('title'),
'content': data.get('content'),
'author': data.get('author')
}
return render(request, 'article.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