Add and improve routes
This commit is contained in:
parent
d9e1c64340
commit
e2a834a56c
@ -1 +0,0 @@
|
|||||||
<h2>Edit bookmark {{ bookmark.id }}</h2>
|
|
5
bookmarks/templates/bookmarks/edit.html
Normal file
5
bookmarks/templates/bookmarks/edit.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{% extends "bookmarks/layout.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Edit bookmark</h2>
|
||||||
|
{% endblock %}
|
@ -1,7 +1,10 @@
|
|||||||
{% extends "bookmarks/layout.html" %}
|
{% extends "bookmarks/layout.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Bookmarks</h2>
|
<div>
|
||||||
|
<h2>Bookmarks</h2>
|
||||||
|
<a href="{% url 'bookmarks:new' %}">Add</a>
|
||||||
|
</div>
|
||||||
<ul class="bookmark-list">
|
<ul class="bookmark-list">
|
||||||
{% for bookmark in bookmarks %}
|
{% for bookmark in bookmarks %}
|
||||||
<li>
|
<li>
|
||||||
@ -12,7 +15,7 @@
|
|||||||
<p>{{ bookmark.description }}</p>
|
<p>{{ bookmark.description }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p>
|
<p>
|
||||||
<a href="{% url 'bookmarks:detail' bookmark.id %}">Edit</a>
|
<a href="{% url 'bookmarks:edit' bookmark.id %}">Edit</a>
|
||||||
<a href="{% url 'bookmarks:remove' bookmark.id %}"
|
<a href="{% url 'bookmarks:remove' bookmark.id %}"
|
||||||
onclick="return confirm('Do you really want to delete this bookmark?')">Remove</a>
|
onclick="return confirm('Do you really want to delete this bookmark?')">Remove</a>
|
||||||
</p>
|
</p>
|
||||||
|
5
bookmarks/templates/bookmarks/new.html
Normal file
5
bookmarks/templates/bookmarks/new.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{% extends "bookmarks/layout.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>New bookmark</h2>
|
||||||
|
{% endblock %}
|
@ -1,10 +1,17 @@
|
|||||||
|
from django.conf.urls import url
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
from django.views.generic import RedirectView
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
app_name = 'bookmarks'
|
app_name = 'bookmarks'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
# Redirect root to bookmarks index
|
||||||
path('bookmark/<int:bookmark_id>', views.detail, name='detail'),
|
url(r'^$', RedirectView.as_view(pattern_name='bookmarks:index', permanent=False)),
|
||||||
path('bookmark/<int:bookmark_id>/remove', views.remove, name='remove'),
|
path('bookmarks', views.index, name='index'),
|
||||||
|
path('bookmarks/new', views.new, name='new'),
|
||||||
|
# path('bookmarks/create', views.create, name='create'),
|
||||||
|
path('bookmarks/<int:bookmark_id>/edit', views.edit, name='edit'),
|
||||||
|
# path('bookmarks/<int:bookmark_id>/update', views.update, name='edit'),
|
||||||
|
path('bookmarks/<int:bookmark_id>/remove', views.remove, name='remove'),
|
||||||
]
|
]
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from django.http import HttpResponse, HttpResponseRedirect
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
@ -18,11 +17,15 @@ def create(request):
|
|||||||
return HttpResponse('OK')
|
return HttpResponse('OK')
|
||||||
|
|
||||||
|
|
||||||
def detail(request, bookmark_id):
|
def new(request):
|
||||||
|
return render(request, 'bookmarks/new.html')
|
||||||
|
|
||||||
|
|
||||||
|
def edit(request, bookmark_id):
|
||||||
context = {
|
context = {
|
||||||
'bookmark': Bookmark.objects.get(bookmark_id)
|
'bookmark': Bookmark.objects.get(pk=bookmark_id)
|
||||||
}
|
}
|
||||||
return render(request, 'bookmarks/detail.html', context)
|
return render(request, 'bookmarks/edit.html', context)
|
||||||
|
|
||||||
|
|
||||||
def remove(request, bookmark_id: int):
|
def remove(request, bookmark_id: int):
|
||||||
|
@ -17,6 +17,6 @@ from django.contrib import admin
|
|||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('bookmarks/', include('bookmarks.urls')),
|
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('', include('bookmarks.urls')),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user