can't display page created with flatpages

(Django 4.0.6)


I’m having trouble displaying a static page I created with flatpages. When I try to reach localhost:8000/apropos, it automatically redirect to localhost:8000/apropos// with a 404 error.

Here are parts of the code of my notices app:

from django.contrib.gis import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin

urlpatterns = [
    path('accounts/', include('django.contrib.auth.urls')),
    path('', include('notices.urls')),
    path('_nested_admin/', include('nested_admin.urls')),
    path('markdownx/', include('markdownx.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


from django.urls import path
from . import views
from django.contrib.flatpages import views as flatviews

app_name = 'notices'

urlpatterns = [
    path('', views.IndexView.as_view(), name='index'),
    path('notices', views.IndexView.as_view(), name='notices'),
    path('notices/<int:pk>', views.DetailView.as_view(), name='detail'),

urlpatterns += [
    path('apropos', flatviews.flatpage, {'url': '/apropos/'}, name='apropos'),


{% extends "notices/base.html" %}

{% load static %}

{% block title %} 
OrAG - {{ flatpage.title }}
{% endblock %}

{% block content %}
{{ flatpage.content }}
{% endblock %}

And screenshot of the apropos page I’d like to create in the flatpages admin (in french, sorry):

Any idea what’s wrong?

Thanks in advance for your help!

For grins and giggles, I’d try either (or both):

  • path('apropos/', flatviews.flatpage, {'url': '/apropos/'}, name='apropos'),

  • path('apropos', flatviews.flatpage, {'url': '/apropos'}, name='apropos'),

(I don’t see anything wrong - so if it were me, I’d be trying a couple things “just to see what happens”. My gut tells me that I think the first option should work.)

Hi Ken,

None of these propositions works in itself, but interestingly, with

urlpatterns += [
    path('apropos', flatviews.flatpage, {'url': '/apropos/'}, name='apropos'),
    path('apropos//', flatviews.flatpage, {'url': '/apropos/'}, name='apropos'),

I’m able to reach the apropos page. The odd redirection is still active though, and it goes to http://localhost:8000/apropos//

It looks like the url that you’re defining in the apropo page is /apropos/. Since it’s not finding a url defined as apropos/, it’s redirecting as apropos//. I’d try removing the trailing slash from that definition in the app.

The thing is that both slashes are mandatory in the flatpages admin and I can’t add the page without them.