Added basic wishlist-paths and simple starter template
This commit is contained in:
parent
4e7cbc5a96
commit
53d83a7855
4 changed files with 33 additions and 3 deletions
9
src/wishlists/templates/public/index.html
Normal file
9
src/wishlists/templates/public/index.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{% if wishlist %}
|
||||||
|
<h1>{{ wishlist.name }}</h1>
|
||||||
|
<sub>Created on {{ wishlist.created_at }}</sub>
|
||||||
|
{% if wishlist.description %}
|
||||||
|
<p>{{ wishlist.description }}</p>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<p>Wishlist not found.</p>
|
||||||
|
{% endif %}
|
|
@ -3,5 +3,7 @@ from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path("public/<uuid:wishlist_id>/", views.public, name="public"),
|
||||||
|
path("owner/<uuid:wishlist_id>/", views.owner, name="owner"),
|
||||||
path("", views.index, name="index"),
|
path("", views.index, name="index"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,5 +1,24 @@
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.template import loader
|
||||||
|
from .models import Wishlist
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("Hello, world. You're at the wishlists index.")
|
return HttpResponse("Hello, world. You're at the wishlists index.")
|
||||||
|
|
||||||
|
|
||||||
|
def owner(request, wishlist_id: UUID):
|
||||||
|
wishlist = Wishlist.objects.get(id=wishlist_id)
|
||||||
|
return HttpResponse(f"You are the owner of wishlist '{wishlist.name}'.")
|
||||||
|
|
||||||
|
|
||||||
|
def public(request, wishlist_id: UUID):
|
||||||
|
wishlist = Wishlist.objects.get(id=wishlist_id)
|
||||||
|
template = loader.get_template("public/index.html")
|
||||||
|
context = {
|
||||||
|
"wishlist": wishlist,
|
||||||
|
}
|
||||||
|
return HttpResponse(template.render(context, request))
|
||||||
|
|
|
@ -16,4 +16,4 @@ Including another URLconf
|
||||||
"""
|
"""
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [path("wishlist/", include("wishlists.urls"))]
|
urlpatterns = [path("", include("wishlists.urls"))]
|
||||||
|
|
Loading…
Reference in a new issue