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

completed lesson_42

parent 04f0bd74
......@@ -12,6 +12,7 @@ body {
font-family: Arial, sans-serif;
font-size: 16px;
color: #444444;
background-color: pink;
}
.container {
......
......@@ -121,14 +121,14 @@ USE_TZ = True
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
os.path.join(BASE_DIR, 'banana')
]
# Media files
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#
#
# # Media files
#
# MEDIA_URL = '/media/'
# MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
......
......@@ -17,9 +17,10 @@ from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path
from web.views import index_view
from web import views
urlpatterns = [
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)
<!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 @@
<p>This is my first Django project!</p>
<h1>{{ greetings|default:"Hello World!" }}</h1>
{% lorem 5 random %}
{% now "SHORT_DATETIME_FORMAT" %}
{% for product, price in products.items %}
{% if forloop.first %}
<hr>
{% elif not forloop.first %}
{% else %}
{% endif %}
<h2>{{ product }} - {{ price }}</h2>
{% if forloop.last %}
<hr>
{% endif %}
{% empty %}
<h1>There are no products :c</h1>
{% endfor %}
<form action="" method="post">
{% csrf_token %}
<input type="text" name="name">
<input type="text" name="surname">
<input type="submit" value="Send">
</form>
<p>Hello World!</p>
</div>
......
......@@ -2,13 +2,31 @@ from django.shortcuts import render
def index_view(request):
return render(
request, 'index.html', context={
'greetings': 'Hello AP-11!'
# 'products': {
# 'Banana': 120,
# 'Apple': 100,
# 'Bread': 70
# }
if request.method == 'POST':
print(request.POST)
else:
print(request.GET)
print(request.GET.get('name'))
print(request.GET.getlist('name'))
return render(
request, 'index.html', context={
'greetings': 'Hello AP-11!'
}
)
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