Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
ap-11_django
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Давид Ли
ap-11_django
Commits
90aa34ed
Commit
90aa34ed
authored
Jun 19, 2023
by
Давид Ли
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lesson 45
parent
a9f2ce94
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
99 additions
and
71 deletions
+99
-71
urls.cpython-311.pyc
my_project/core/__pycache__/urls.cpython-311.pyc
+0
-0
urls.py
my_project/core/urls.py
+3
-1
db.sqlite3
my_project/db.sqlite3
+0
-0
views.cpython-311.pyc
my_project/web/__pycache__/views.cpython-311.pyc
+0
-0
article.html
my_project/web/templates/article.html
+7
-10
article_create.html
my_project/web/templates/article_create.html
+22
-25
base.html
my_project/web/templates/base.html
+42
-0
index.html
my_project/web/templates/index.html
+20
-32
views.py
my_project/web/views.py
+5
-3
No files found.
my_project/core/__pycache__/urls.cpython-311.pyc
View file @
90aa34ed
No preview for this file type
my_project/core/urls.py
View file @
90aa34ed
...
@@ -21,7 +21,9 @@ from web import views
...
@@ -21,7 +21,9 @@ from web import views
urlpatterns
=
[
urlpatterns
=
[
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
''
,
views
.
index_view
),
path
(
''
,
views
.
index_view
,
name
=
'main-page'
),
path
(
'articles/add/'
,
views
.
article_create_view
,
name
=
'articles-add'
),
path
(
'articles/add/'
,
views
.
article_create_view
,
name
=
'articles-add'
),
# /articles/1/ OR /articles/?id=1
# article_details_view(request, id)
path
(
'articles/<int:id>/'
,
views
.
article_detail_view
,
name
=
'articles-detail'
),
path
(
'articles/<int:id>/'
,
views
.
article_detail_view
,
name
=
'articles-detail'
),
]
+
static
(
settings
.
MEDIA_URL
,
document_root
=
settings
.
MEDIA_ROOT
)
]
+
static
(
settings
.
MEDIA_URL
,
document_root
=
settings
.
MEDIA_ROOT
)
my_project/db.sqlite3
View file @
90aa34ed
No preview for this file type
my_project/web/__pycache__/views.cpython-311.pyc
View file @
90aa34ed
No preview for this file type
my_project/web/templates/article.html
View file @
90aa34ed
<!DOCTYPE html>
{% extends 'base.html' %}
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Title
</title>
</head>
<body>
<h1>
Article
</h1>
{% block title %}
<h1>
Article checkout
</h1>
{% endblock %}
{% block content %}
<h2>
{{ article.title }}
</h2>
<h2>
{{ article.title }}
</h2>
<p>
{{ article.text }}
</p>
<p>
{{ article.text }}
</p>
...
@@ -15,5 +13,4 @@
...
@@ -15,5 +13,4 @@
<h4>
Created: {{ article.created_at }}
</h4>
<h4>
Created: {{ article.created_at }}
</h4>
<h4>
Updated: {{ article.updated_at }}
</h4>
<h4>
Updated: {{ article.updated_at }}
</h4>
</body>
{% endblock %}
</html>
\ No newline at end of file
my_project/web/templates/article_create.html
View file @
90aa34ed
<!DOCTYPE html>
{% extends 'base.html' %}
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Create
</title>
</head>
<body>
<h1>
Create Article
</h1>
{% block title %}
<form
action=
"/articles/add/"
method=
"post"
>
<h1>
Create Article
</h1>
{% csrf_token %}
{% endblock %}
<label>
Title:
</label><br/>
<input
type=
"text"
name=
"title"
/><br/>
<label>
Text:
</label><br/>
{% block content %}
<textarea
name=
"text"
></textarea><br/>
<form
action=
"/articles/add/"
method=
"post"
>
{% csrf_token %}
<label>
Author:
</label><br/>
<div
class=
"mb-3"
>
<input
type=
"text"
name=
"author"
/><br/>
<label
for=
"titleId"
class=
"form-label"
>
Title
</label>
<input
type=
"text"
name=
"title"
class=
"form-control"
id=
"titleId"
aria-describedby=
"title"
>
<br/>
</div>
<input
type=
"submit"
value=
"Send"
/>
<div
class=
"mb-3"
>
<label
for=
"textId"
class=
"form-label"
>
Text
</label>
</form>
<textarea
name=
"text"
class=
"form-control"
id=
"textId"
cols=
"30"
rows=
"10"
></textarea>
</div>
</body>
<div
class=
"mb-3"
>
</html>
<label
for=
"authorId"
class=
"form-label"
>
Author
</label>
<input
type=
"text"
name=
"author"
class=
"form-control"
id=
"authorId"
aria-describedby=
"author"
>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
Submit
</button>
</form>
{% endblock %}
my_project/web/templates/base.html
0 → 100644
View file @
90aa34ed
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<link
rel=
"stylesheet"
href=
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.1/css/bootstrap.min.css"
integrity=
"sha512-Ez0cGzNzHR1tYAv56860NLspgUGuQw16GiOOp/I2LuTmpSK9xDXlgJz3XN4cnpXWDmkNBKXR/VDMTCnAaEooxA=="
crossorigin=
"anonymous"
referrerpolicy=
"no-referrer"
/>
<title>
Title
</title>
</head>
<body>
<nav
class=
"navbar navbar-expand-lg navbar-light bg-light"
>
<div
class=
"container"
>
<a
class=
"navbar-brand"
href=
"{% url 'main-page' %}"
>
Articles
</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 flex-grow-0"
id=
"navbarNav"
>
<ul
class=
"navbar-nav"
>
<li
class=
"nav-item"
>
<a
class=
"nav-link active"
aria-current=
"page"
href=
"{% url 'articles-add' %}"
>
Create
</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>
</ul>
</div>
</div>
</nav>
<div
class=
"container"
>
{% block title %}{% endblock %}
{% block content %}{% endblock %}
</div>
{% block script %}{% endblock %}
</body>
</html>
\ No newline at end of file
my_project/web/templates/index.html
View file @
90aa34ed
{% extends 'base.html' %}
{% load static %}
{% load static %}
<!doctype html>
<html
lang=
"en"
>
{% block content %}
<head>
<h1>
Articles
</h1>
<meta
charset=
"UTF-8"
>
<a
href=
"{% url 'articles-add' %}"
class=
"btn btn-primary"
>
Создать
</a>
<meta
name=
"viewport"
{% for article in articles %}
content=
"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
>
<br>
<meta
http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
<hr>
<link
rel=
"stylesheet"
href=
"{% static 'css/styles.css' %}"
>
<br>
<link
rel=
"stylesheet"
href=
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.1/css/bootstrap.min.css"
integrity=
"sha512-Ez0cGzNzHR1tYAv56860NLspgUGuQw16GiOOp/I2LuTmpSK9xDXlgJz3XN4cnpXWDmkNBKXR/VDMTCnAaEooxA=="
crossorigin=
"anonymous"
referrerpolicy=
"no-referrer"
/>
<h2>
{{ article.title }}
</h2>
<title>
Hello
</title>
<p>
</head>
<a
href=
"{% url 'articles-detail' id=article.id %}"
>
<body>
Подробнее
<div
class=
"container"
>
</a>
<h1>
Articles
</h1>
</p>
<a
href=
"{% url 'articles-add' %}"
class=
"btn btn-primary"
>
Создать
</a>
<br>
{% for article in articles %}
<hr>
<br>
<br>
<hr>
{% endfor %}
<br>
{% endblock %}
<h2>
{{ article.title }}
</h2>
\ No newline at end of file
<p>
<a
href=
"{% url 'articles-detail' id=article.id %}"
>
Подробнее
</a>
</p>
<br>
<hr>
<br>
{% endfor %}
</div>
</body>
</html>
\ No newline at end of file
my_project/web/views.py
View file @
90aa34ed
from
django.shortcuts
import
render
,
redirect
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
django.urls
import
reverse
from
web.models
import
Article
from
web.models
import
Article
...
@@ -6,7 +7,8 @@ from web.models import Article
...
@@ -6,7 +7,8 @@ from web.models import Article
def
index_view
(
request
):
def
index_view
(
request
):
return
render
(
return
render
(
request
,
'index.html'
,
context
=
{
request
,
'index.html'
,
context
=
{
'articles'
:
Article
.
objects
.
order_by
(
'title'
)
'articles'
:
Article
.
objects
.
order_by
(
'title'
),
'reverse'
:
reverse
(
'articles-detail'
,
kwargs
=
{
'id'
:
1
})
}
}
)
)
...
@@ -30,5 +32,5 @@ def article_create_view(request):
...
@@ -30,5 +32,5 @@ def article_create_view(request):
# /articles/{id}
# /articles/{id}
def
article_detail_view
(
request
,
id
:
int
):
def
article_detail_view
(
request
,
id
:
int
):
article
=
Article
.
objects
.
get
(
id
=
id
)
article
=
get_object_or_404
(
Article
,
id
=
id
)
return
render
(
request
,
'article.html'
,
context
=
{
'article'
:
article
})
return
render
(
request
,
'article.html'
,
context
=
{
'article'
:
article
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment