2

I have installed django-comments-xtd following the quick start guide in the documentation here.

When I go to access the /comments URL, I only get a 404 error, and the message 'Raised by: wagtail.wagtailcore.views.serve'.

I followed the documentation without issue, and have installed other apps that work fine such as django-machina.

I am using django 1.11.13, python 2.7 and django-comments-xtd 2.1.0.

Why would this particular URL not be accessible? Templates exist in the correct location.

My files are setup exactly the same as in the documentation, happy to provide more info but not sure what to provide right now.

What can I do to try and troubleshoot the problem?

Jake Rankin
  • 714
  • 6
  • 22
  • I don't know django-comments-xtd. But there are two obvious things you can check. 1. Is django-comments-xtd before wagtail apps and after your app in installed apps? 2. Is django-comments-xtd urls befrore wagtail urls? – allcaps Jun 14 '18 at 06:30
  • Thanks for your suggestions, but it is not that easy. All the comments stuff is before the wagtail stuff in all instances. – Jake Rankin Jun 14 '18 at 06:35
  • @Zev thanks for investigating further. What would be the way to do the bad workaround? Maybe put that as an answer since it might be the best solution atm? – Jake Rankin Jun 16 '18 at 23:57
  • I don't think I should be tied to Python2 for any reason...would appreciate more info, thank you for your assistance. – Jake Rankin Jun 17 '18 at 02:40
  • @Zev I upgraded my project to wagtail 2.1 and python 3.6 and it is working ok, however I get the exact same error/problem when trying to access comments. Guess it is not a version issue? – Jake Rankin Jun 17 '18 at 23:36

3 Answers3

2

I think you are misreading the documentation and you do not actually have a problem. It just says:

mount the URL patterns of django_comments_xtd in the path /comments/

It does not say that you should access this URL. The fact that, as per your comment, you are not getting a 404 when you are accessing /comments/sent/ indicates that you have set up django-comments-xtd correctly.

For /comments/ to be a valid URL, the django_comments_xtd.urls you included would have to contain an empty URL pattern, like this:

url('', some_view)

If you look at the urls.py of django-comments-xtd, you will see that it does indeed include the urls.py from django-contrib-comments, but this doesn't define an empty URL pattern. So there is no URL pattern that would match /comments/.

Daniel Hepper
  • 28,981
  • 10
  • 72
  • 75
  • When I was trying to figure this out, my expectation was for Django to handle the 404 rather than Wagtail. So Django would list the api of comments such as: `Using the URLconf defined in sandbox.urls, Django tried these URL patterns, in this order:` `1. ^comments/ ^sent/$ [name='comments-xtd-sent']` `2. ^comments/ ^sent\.(?P[a-z0-9]+)/?$ [name='comments-xtd-sent']` `3. ^comments/ ^confirm/(?P[^/]+)/$ [name='comments-xtd-confirm']` `4. ^comments/ ^confirm/(?P[^/]+)\.(?P[a-z0-9]+)/?$ [name='comments-xtd-confirm']` – Zev Jun 21 '18 at 11:29
  • Jake will have to answer for himself, but if the suburls work, that are defined, maybe the question isn't as important as I'd thought. However, I'd still like to figure out how to tell Wagtail to completely ignore a folder (say I had a custom 404 page for wagtail and a custom one for comments/ and I wanted to choose which to display). Also, I do find the listing of URL patterns django tried useful for debugging and coding (rather than production where it wouldn't be displayed anyway). – Zev Jun 21 '18 at 11:33
  • Also comments/api/feedback/ may be a better url for Jake to try because comments/sent is expecting a more complicated request than just displaying a page. – Zev Jun 21 '18 at 11:43
  • 1
    @Zev 1. If a view returns a 404, Django will not display the URL patterns, because there actually was a matching URL pattern. The [django-extensions package](https://django-extensions.readthedocs.io) provides a [show_urls](https://django-extensions.readthedocs.io/en/latest/command_extensions.html?highlight=show_urls) management command that might help in this case. 2. You would have to exclude the URL in the URL pattern, if you don't want it to be handled by wagtail, e.g. `r"^(?!comments/)"`. 3. you are right, but `/comments/sent/` should at least do something and not be handled by Wagtail – Daniel Hepper Jun 21 '18 at 11:54
  • Hmmm, I tried regex expressions to exclude comments but I must have done it wrong because that one works. I think I missed the `^`. Can you edit your answer to include that? – Zev Jun 21 '18 at 12:32
  • There is no difference omitting or including a slash for me, and if I omit it it seems Chrome adds one. Getting /comments to display is the final step in the documentation for installing and setting up django-comments-xtd. accessing /comments/sent gives a BadSignature error and /comments/api/feedback/ gives a template not found error, looks like it is looking for rest-framework files. – Jake Rankin Jun 21 '18 at 18:33
  • @Jake yes, I was wrong about the trailing slash, it doesn't make a difference. But I stand by my point that `/comments/` is just not a valid URL. I've reworded my answer, hoping that it now makes more sense to you. – Daniel Hepper Jun 21 '18 at 19:21
  • Thank you for that...what an embarrassing mistake to make, I am still learning all of this from scratch really thought I was meant to go to /comments. @Zev Thank you for your help and I am sorry for wasting your time and bounty points. – Jake Rankin Jun 21 '18 at 21:25
  • 2
    @JakeRankin no worries, sometimes you don’t see the forest for the tree and you need some external input to overcome that. As far as I can tell, this will still happen after a decade of professional experience ;) – Daniel Hepper Jun 22 '18 at 05:37
0

The urls definition from django-comments-xtd will have to come before Wagtail's one (i.e. url(r'', include(wagtail_urls))) as it acts as a catch all and will therefore render other urls unreachable.

Loïc Teixeira
  • 1,404
  • 9
  • 19
  • It is before wagtails url entry. I have it right after my forum entry which works fine, both are before the wagtail entry. – Jake Rankin Jun 14 '18 at 06:33
0

just food for thought. The email confirmation template uses

<a href="http://{{ site.domain }}{{ confirmation_url }}">http://{{ site.domain }}{{ confirmation_url|slice:":40" }}...</a>

You want to make sure your site.domain matches whatever your are using for development. This just fixed this error for me. I had a different domain setup in Django Admin