question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RoutablePageMixin URLs which include "." are not routable

See original GitHub issue

I just lost 2 hours of work due to my ignorance of Wagtail’s page routing regex. Which is unsurprising, because it’s completely undocumented.

I was utterly baffled as to why the RoutablePageMixin code that I wrote to create an RSS feed for my NewsIndexPages was not being executed. I eventually had to fire up the debugger and dig deep into the resolver code to figure out why django was throwing a 404 from example.com/news/feed.rss, even though example.com/news worked just fine. I had the feed route very clearly defined with:

@route(r'^feed\.rss$')
rss_feed(self, request):
   ...

Turns out that the culprit is in wagtailcore/utls.py:

if WAGTAIL_APPEND_SLASH:
    serve_pattern = r'^((?:[\w\-]+/)*)$'
else:
    serve_pattern = r'^([\w\-/]*)$'

Because serve_pattern doesn’t include \. in its regex, example.com/news/feed.rss will never even engage the Page serving mechanism. Django cycles through your site’s URL patterns, sees nothing that matches serve_pattern, and gives up before calling any Wagtail code.

Now I’m not sure what the proper remedy for this would be. I’m assuming there’s some sort of reason that . is excluded from serve_pattern, so simply adding it doesn’t sound like a valid solution. I notice also that the javascript on the Page edit form prevents you from adding a . to a Page’s slug.

So that means a documentation update would probably be appropriate. Perhaps the RoutablePageMixin instructions should state which characters are valid for use in @route() regexes? I’d be happy to write a PR for that if you think it’s a good solution.

Note, too, that I had to contend with the bug acknowledged in #2871, since I use WAGTAIL_APPEND_SLASH = False. Fortunately, that wasn’t nearly so frustration-inducing.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
darthmallcommented, Sep 4, 2019

Just ran into this bug trying to create a routable page (for a product) that would resolve URLs for release notes of the product of the form <product>/releases/5.3 and <product>/releases/5.3.1, in case you’re looking for real world use cases to motivate fixing the bug. 😁

For now I’ll just use a valid slug of the version number to avoid the issue, but it’d be great to get this fixed. 🙏 😁

2reactions
gasmancommented, Sep 18, 2019

From a quick dig into RFC 3986, I think the full set of punctuation characters we should be accepting in path components is:

- . _ ~ % ! $ & ' ( ) * + , ; = : @

There might be edge cases when it comes to things like Unicode (at the protocol level URLs don’t allow it, but it depends whether Django sees the raw URL or an unescaped version) - but allowing the above set should solve the immediate use-cases (while avoiding the “what happens with slashes and question marks” concerns that we’d get from allowing everything).

Read more comments on GitHub >

github_iconTop Results From Across the Web

RoutablePageMixin - Wagtail's documentation
The RoutablePageMixin mixin provides a convenient way for a page to respond on multiple sub-URLs with different views. For example, a blog section...
Read more >
How to use routablepageurl tag in wagtail HTML template
routablePageMixin is a Page mixin that allows the use of multiple sub-page routes to be made available, each with a name with a...
Read more >
Wagtail Routable Page - AccordBox
I will show you how to use RoutablePageMixin to make blog app routable, so it can handle sub-URLs like category and tag links....
Read more >
Routable Page Categories And Years - LearnWagtail.com
This time we'll add URL parameters and filter pages based on a custom route. Below is the code you can use. Please note,...
Read more >
Wagtail CMS: Routable Page Categories And Years - YouTube
In this tutorial we'll add /blog/category/{category_name}/ and filter pages based on the slug in the URL. For more free tutorials: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found