Search code examples
djangodjango-urlsdjango-2.1

Page not found, URL not resolved


I am trying to call a function in my views.py by pasting a url http://127.0.0.1:8000/upload_results/UniEX_HG1_A15 in the web browser, but the request fails and I can not see why my URL pattern does not work.

The error:

Page not found (404)
Request Method:     GET
Request URL:    http://127.0.0.1:8000/upload_results/UniEX_HG1_A15

Using the URLconf defined in varview.urls, Django tried these URL patterns, in this order:

    ^$ [name='show_index']
    ^admin/
    ^upload/ [name='varview_submission']
    ^upload_results/(?P<project_id>[0-9A-Za-z_]+)/ [name='varview_upload_results']
    ^validate/(?P<project_id>[0-9A-Za-z_]+)/ [name='varview_validate']
    ^filterallprojects/[0-9A-Za-z_]+ [name='varview_filterallprojects']
    ^project/(?P<project_id>[0-9A-Za-z_]+)/wgsmetrics/ [name='varview_wgsmetrics']
    ^project/(?P<project_id>[0-9A-Za-z_]+)/targetgenecoverage/ [name='varview_targetgenecoverage']
    ^project/(?P<project_id>[0-9A-Za-z_]+)/(?P<display_option>[0-9A-Za-z_]+)/ [name='varview_project']
    ^media\/(?P<path>.*)$

The current path, upload_results/UniEX_HG1_A15, didn't match any of these.

And here is my urls.py:

from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from varview import views
from varview.forms import DataUploaderForm1, DataUploaderForm2, GetProjectIdForm

urlpatterns = [
    url(r'^$', views.show_index, name='show_index'),
    url(r'^admin/', admin.site.urls),
    url(r'^upload/', views.init_submission, name='varview_submission'),
    url(r'^upload_results/(?P<project_id>[0-9A-Za-z_]+)/', views.upload_results, name='varview_upload_results'), 
]

This already worked some time ago, but in the meantime I did many changes. Latest change was to include celery (djcelery). The index page and others still work. I already read many posts related to django-url, but could not figure it out.

Thank you for your help.


Solution

  • Note your URL has a trailing slash,

    ^upload_results/(?P<project_id>[0-9A-Za-z_]+)/
    

    but you are trying to access a URL without the trailing slash

    /upload_results/UniEX_HG1_A15
    

    Normally, Django will redirect to the URL with the trailing slash. Perhaps your MIDDLEWARE setting is incorrect, or you have set APPEND_SLASH to False.