Django can't recognize 0,1,2 precisely in url


from django.http import HttpResponse,HttpResponseRedirect

articles = {
    'index' : "Hello this is a view inside my_app",
    'simple' : 'simple views',
    'sports' : 'Sports Page',
    'finance' : 'Finance Page',
    'politics' : "Politics Page"

def news_view(request, topic) :
    try :
        return HttpResponse(articles[topic]) 
        raise Http404("404 GENERIC ERROR") 

def num_page_view(request,num):
    topics_list = list(articles.keys())
    topic = topics_list[num]
    return HttpResponseRedirect(topic)

from django.urls import path
from . import views

urlpatterns = [

when i type /my_app/0, django automatically change 0 0/, so i think Django can't recognize that this page's parameter is pure int. It continues until I type 0,1,2

But when i type more than 2 (ex. /my_app/3), it works as i intended (1. enter /my_app/3 2. redirect to /my_app/finance/)

I don't know why Django do recognize the int parameter more than 2 but not 0,1,2.


  1. enter /my_app/0
  2. redirect to /my_app/index/


  1. enter my_app/0
  2. url is automatically changed to my_app/0/
  3. can't redirect to the page so i got an error
Back to Top