From 84c17ff5edb572a3ef86c5307430f5e1f904707a Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 13 Nov 2022 20:47:41 +0100 Subject: [PATCH] Update web tutorial with django path variable. Close 2664. --- .../source/Howtos/Web-Character-Generation.md | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/docs/source/Howtos/Web-Character-Generation.md b/docs/source/Howtos/Web-Character-Generation.md index e1115cf323..2e60fb7d8a 100644 --- a/docs/source/Howtos/Web-Character-Generation.md +++ b/docs/source/Howtos/Web-Character-Generation.md @@ -364,16 +364,16 @@ created in `mygame/web/chargen/urls.py`. ```python # file mygame/web/chargen/urls.py -from django.conf.urls import url +from django.urls import path from web.chargen import views urlpatterns = [ - # ex: /chargen/ - url(r'^$', views.index, name='index'), - # ex: /chargen/5/ - url(r'^(?P[0-9]+)/$', views.detail, name='detail'), - # ex: /chargen/create - url(r'^create/$', views.creating, name='creating'), + # url: /chargen/ + path("", views.index, name='chargen-index'), + # url: /chargen/5/ + path("/", views.detail, name="chargen-detail"), + # url: /chargen/create + path("create/", views.creating, name='chargen-creating'), ] ``` @@ -381,29 +381,20 @@ You could change the format as you desire. To make it more secure, you could rem "detail" url, and instead just fetch the account’s applications using a unifying field like account_id to find all the character application objects to display. -We must also update the main `mygame/web/urls.py` file (that is, one level up from our chargen app), -so the main website knows where our app's views are located. Find the `patterns` variable, and +To add this to our website, we must also update the main `mygame/website/urls.py` file; this +will help tying our new chargen app in with the rest of the website. `urlpatterns` variable, and change it to include: ```python -# in file mygame/web/urls.py +# in file mygame/website/urls.py -from django.conf.urls import url, include +from django.urls import path, include -# default evennia patterns -from evennia.web.urls import urlpatterns - -# eventual custom patterns -custom_patterns = [ - # url(r'/desired/url/', view, name='example'), +urlpatterns = [ + # make all chargen endpoints available under /chargen url + path("chargen/", include("web.chargen.urls") ] -# this is required by Django. -urlpatterns += [ - url(r'^chargen/', include('web.chargen.urls')), -] - -urlpatterns = custom_patterns + urlpatterns ``` ### URLs - Checkpoint: @@ -517,7 +508,7 @@ up on documentation elsewhere on the web for GET vs. POST. After finishing this tutorial you should have edited or created the following files: ```bash -mygame/web/urls.py +mygame/web/website/urls.py mygame/web/chargen/models.py mygame/web/chargen/views.py mygame/web/chargen/urls.py