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

webinar 21

parent d4d90c52
......@@ -22,5 +22,6 @@ from web import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index_view),
path('articles/add/', views.article_create_view)
path('articles/add/', views.article_create_view, name='articles-add'),
path('articles/<int:id>', views.article_detail_view, name='articles-detail'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
......@@ -6,25 +6,7 @@
</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>
<h1>Article</h1>
<h2>{{ title }}</h2>
<p>{{ content }}</p>
......
from django.shortcuts import render
from django.shortcuts import render, redirect
def index_view(request):
......@@ -19,7 +19,8 @@ def article_create_view(request):
context = {}
if request.method == 'GET':
print(request.GET.get('name'))
# return render(request, 'article_create.html')
return render(request, 'article_create.html')
elif request.method == 'POST':
print(request.POST)
data = request.POST
......@@ -29,4 +30,9 @@ def article_create_view(request):
'author': data.get('author')
}
return render(request, 'article.html', context)
return redirect('articles-add', foo='bar')
# /articles/{id}
def article_detail_view(request, title: str):
return render(request, 'article.html', context={'title': title})
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