0

So after upgrading to Django 1.9, I have this strange issue with ListViews and url matching. Everything works fine in development, but my views which subclass ListView throw 404s in production (CherryPy/IIS using FORCE_SCRIPT_NAME = '/project'):

404 Error msg:

    Using the URLconf defined in project.urls, Django tried these URL patterns, in this order:
         1. ^$ [name='home']
         2. ^things/
         3. ^otherstuff/
    The current URL, project/things/, didn't match any of these.

Project main urls.py:

    urlpatterns = [
        url(r'^$', RedirectView.as_view(url=reverse_lazy("start")), name="home"),
        url(r'^things/', include('things.urls')),
        url(r'^otherstuff/', include('otherstuff.urls'))
    ]

Things urls.py:

    urlpatterns = [

        url(r'^start/$', views.Start.as_view(), name="start"),
        url(r'^dashboard/$', views.Dashboard.as_view(), name="dashboard"),
        url(r'^stats/$', views.Statistics.as_view(), name="statistics"),

        # --- Trouble here ---
        url(r'^$', views.AllThingsList.as_view(), name="all-things"),
        url(r'^sublistthings/$', views.ThingsSubList.as_view(), name="sub-list-things"),
        # --- End trouble ---

        url(r'^selectthing/$', views.SelectThing.as_view(), name="select-thing"),
        url(r'^(?P<pk>\d+)/$', views.Thing.as_view(), name="thing")
    ]

Every url matches fine, except for the ones I've marked as trouble. The views relating to these urls extend the following class:

    class BaseThingsListView(ListView):

        def get(self, request, *args, **kwargs):
            """
            return regular list view on page load and then json data on
            datatables ajax request.
            """

            ...

            self.object_list = self.get_queryset()

            # --- Trouble here ---
            if not self.request.is_ajax():
                return super(BaseThingsListView, self).get(request, *args, **kwargs)
            # --- End Trouble ---                

            ...

            context = {ajax_stuff}
            return HttpResponse(json.dumps(context), content_type='application/json')

        # Other methods include:
        def get_table_context_data(self, **kwargs):
        def get_context_data(self, *args, **kwargs):
        def get_header_for_field(self, field):
        def set_page(self):
        def get_paginate_by(self, queryset):
        def get_queryset(self):
        def filter_queryset(self, qs):
        def order_queryset(self, qs):
        def get_rows(self, objects):
        def format_col(self, field, obj):
        def set_query_params(self):

If I comment out the troubled part above, an ajax object is returned as expected and no 404 thrown. Also note that allow_empty is True, and that would raise a different error message anyways.

So what is it about returning ListViews's get() that causes this in production only? Or is the issue somewhere else?

UPDATE:

A django.core.urlresolvers.Resolver404 is generated in \django\template\backends\django.py line 95 in class Template(object):

        return self.template.render(context)

...which the debugger takes and generates the misleading 404 msg. Could my template loaders by set incorrectly? Really not sure where to go from here.

BottleZero
  • 893
  • 6
  • 13

1 Answers1

0

You have broken urls.py url(r'^sublistthings/$', views.ThingsSubList.as_view(), name="sub-list-things"),name="complete-details"), you made an error by placing additional name="complete-details"),

And also there is no url that match '^script_name/' pattern

vishes_shell
  • 22,409
  • 6
  • 71
  • 81
  • Oops, the first error was one I made transcribing the code to here. `script_name` is appended when using FORCE_SCRIPT_NAME. I've edited to show something that makes more sense. – BottleZero Mar 04 '16 at 18:53