Hi all,
I am new to Django. I am completing an online course and trying to deploy an app using PlanetHoster. The project (my_site
) consists of a single app (blog
) (in addition to admin
). Everything works perfectly using localhost:8000
. In PlanetHoster I created the application my_site
and the corresponding url is my_domain/my_site
.
It works except that my hyperlinks (and in fact the urls to my static files too) are incorrect:
instead of having a url such as my_domain/my_site/posts/
, I get my_domain/my_sit/posts/
(the trailing e in my_site
gets dropped)!
Here is urls.py at the project level (my_site
):
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Here is urls.py at the app level (blog
):
urlpatterns = [
path("", views.StartingPageView.as_view(), name='starting-page'),
path("posts/", views.AllPostsView.as_view(), name='posts-page'),
path("posts/<slug:slug>/", views.SinglePostView.as_view(), name='post-detail-page'),
path("read-later/", views.ReadLaterView.as_view(), name="read-later"),
]
I can get it to work if I replace path('', include('blog.urls'))
in the project urls.py with path('blog/', include('blog.urls'))
. (Of course, in that case, all the blog urls then become my_domain/my_site/blog/...
.)
I have been trying to figure out what I am not doing right for several days. To no avail! Could you point out what I am missing?