0

I am trying to catch all URLs from the safer app and send them to a catch all view; for example: http://127.0.0.1:8000/saferdb/123
http://127.0.0.1:8000/saferdb/12

I think I have an issue with my reg ex in url.py:

from django.conf.urls import url
from . import views

app_name = 'saferdb'
urlpatterns = [
    url(r'^/$', views.index, name='index'),
    url(r'^(?P<pk>[0-9]+)/$', views.detail, name='detail'),
]

Views.py is the sample code from the django tutorial:

from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse
from .models import Question

def index(request):
    latest_question_list = Question.objects.all()[:5]
    output = ', '.join([q.DOT_Number for q in latest_question_list])
    return HttpResponse(output)


def detail(request, question_id):
    return HttpResponse("You're looking at question %s." % question_id)

I noticed that /saferdb/ will not work unless the reg ex contains a slash: r'^/$' instead of r'^$' as shown in the django tutorial.

2
  • 1
    Show your main project urls.py. Commented Dec 7, 2017 at 13:48
  • add a / at the end of the /saferdb in the main urls.py file. Commented Dec 7, 2017 at 13:50

1 Answer 1

1

Please add '/' at the end of url in root urls.py of 'safer' app, something similar to this:

url(r'^saferdb/', include('saferdb.urls', namespace='saferdb'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.