What is the url.py file that opens home using wagtail?

Viewed 921

I'm starting using Wagtail + Django.

Generally, in Django you set the urls path in a urls.py file.

However, I cannot find the url.py that says to my app, when users visits main domain (local http://127.0.0.1:8000/) show home_page.html view.

I'm following the get_started tutorial.

And used this command to generate the basic apps:

wagtail start elim

This generated: a) elim, b) home, c) search apps.

Only elim app contains a urls.py, but it doesn't set a path for home:

from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin

from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls

from search import views as search_views

urlpatterns = [
    url(r'^django-admin/', admin.site.urls),

    url(r'^admin/', include(wagtailadmin_urls)),
    url(r'^documents/', include(wagtaildocs_urls)),

    url(r'^search/$', search_views.search, name='search'),

]

This is my project structure:

enter image description here

So how does going to "/" open the home page???

enter image description here

enter image description here

2 Answers

The home dir is served by wagtail internal mechanism. Scroll to the end of the file elim/urls.py to find this :

urlpatterns = urlpatterns + [
    # For anything not caught by a more specific rule above, hand over to
    # Wagtail's page serving mechanism. This should be the last pattern in
    # the list:
    url(r"", include(wagtail_urls)),

    # Alternatively, if you want Wagtail pages to be served from a subpath
    # of your site, rather than the site root:
    #    url(r"^pages/", include(wagtail_urls)),
]

So, continue to read the tutorial, I'm sure you will soon or later discover the Page models and everything provided by wagtail.

Try adding a view function in your app's views.py file that renders home_page.html when the user goes to "/".

in views.py write this:

def home_page(response):
    return render(response, "home/home_page.html")

then map this to ur urs.py file

url_patterns = [
path("", views.home_page)

]

then add this url to your url conf

Related