Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
django-url-follower
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikolaos S. Papaspyrou
django-url-follower
Commits
2b369b88
Commit
2b369b88
authored
Jun 15, 2015
by
Nikolaos S. Papaspyrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add part 4c, views using templates
parent
ad233b72
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
5 deletions
+33
-5
README.md
README.md
+3
-0
details.html
urlapp/templates/details.html
+8
-0
index.html
urlapp/templates/index.html
+14
-0
views.py
urlapp/views.py
+8
-5
No files found.
README.md
View file @
2b369b88
...
@@ -98,3 +98,6 @@ Edit `redurl/urls.py`.
...
@@ -98,3 +98,6 @@ Edit `redurl/urls.py`.
Make views that do something, just reading the objects' data.
Make views that do something, just reading the objects' data.
Make views using templates.
Edit
`urlapp/views.py`
.
Create
`urlapp/templates/index.html`
and
`urlapp/templates/details.html`
.
urlapp/templates/details.html
0 → 100644
View file @
2b369b88
<h1>
Details of URL {{ url.id }}
</h1>
<ul>
<li>
Owner: {{ url.user.first_name }} {{ url.user.last_name }}
({{ url.user.username }})
</li>
<li>
Target:
<a
href=
"{{ url.target }}"
target=
"_blank"
><code>
{{ url.target }}
</code></a></li>
<li>
Followed: {{ url.used }} time(s).
</li>
</ul>
urlapp/templates/index.html
0 → 100644
View file @
2b369b88
<h1>
List of URLs
</h1>
{% if url_list %}
<ul>
{% for u in url_list %}
<li>
<a
href=
"/url={{ u.id }}/"
>
Show details
</a>
, or follow
<a
href=
"/{{ u.id }}/"
target=
"_blank"
><code>
{{ u.target }}
</code></a>
</li>
{% endfor %}
</ul>
{% else %}
<p>
No URLs are available.
</p>
{% endif %}
urlapp/views.py
View file @
2b369b88
...
@@ -6,13 +6,16 @@ from .models import Url
...
@@ -6,13 +6,16 @@ from .models import Url
# Create your views here.
# Create your views here.
def
index
(
request
):
def
index
(
request
):
L
=
Url
.
objects
.
all
()
context
=
{
output
=
', '
.
join
([
u
.
target
for
u
in
L
])
'url_list'
:
Url
.
objects
.
all
()
return
HttpResponse
(
output
)
}
return
render
(
request
,
'index.html'
,
context
)
def
redir
(
request
,
url_id
):
def
redir
(
request
,
url_id
):
return
HttpResponse
(
"You're following URL {}."
.
format
(
url_id
))
return
HttpResponse
(
"You're following URL {}."
.
format
(
url_id
))
def
url
(
request
,
url_id
):
def
url
(
request
,
url_id
):
u
=
Url
.
objects
.
get
(
id
=
url_id
)
context
=
{
return
HttpResponse
(
"URL {} goes to {}."
.
format
(
url_id
,
u
.
target
))
'url'
:
Url
.
objects
.
get
(
id
=
url_id
)
}
return
render
(
request
,
'details.html'
,
context
)
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