- It's much easier to troubleshoot if you provide the full stack-trace, as is. It helps answer questions like
- Which URL were you requesting that ultimately gave you this 404?
- Which URL patterns were "tried" or were regex-compared to the reqest
- It looks like you're trying to capture task_id from the url (e.g. "api/1/" -> task_id = 1). You should use captured_parameters for this (i.e. "url(r'^(?P<task_id>\d{1,2})/$', api)")
- Review the Django docs for how views are defined; Instead of (self, task_id) as your api view arguments you probably meant (request, task_id).
- Note that '$' ends a regular expression, so calls like "api/1/detail/" will 404.
- Your regex is requiring a closing slash on the url, which is okay for the most part, but "api/1" will not work if you've modified the APPEND_SLASH setting.
On Saturday, July 4, 2015 at 8:41:31 AM UTC-4, Wanare Piyush 13MCC1056 wrote:
I am getting this error :-
You're seeing this error because you have DEBUG = True
in your Django settings file. Change that toFalse
, and Django will display a standard 404 page.
My views.py file:-
from django.http import HttpResponse
import datetime
from django.template import Template, Context
from django.template.loader import get_template
from django.http import Http404
tasks = [
{
'id': 1,
'title': u'Buy groceries',
'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
'done': False
},
{
'id': 2,
'title': u'Learn Python',
'description': u'Need to find a good Python tutorial on the web',
'done': False
}
]
#task_id=='1'
def api(self,task_id):
#task=[task if task['id']=='task_id' for task in tasks ]
task = [task for task in tasks if task['id'] == task_id]
if len(task) == 0:
raise Http404
return HttpResponse(tasks)
My urls.py file:-
"""Dj1 URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin
#from App1.views import place_order_form
from App1.views import api
urlpatterns = [
#url(r'^admin/', include(admin.site.urls)),
url(r'^api/(\d{1,2})/$',api),
#url(r'^place_order/$',place_order_form),
]
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ceef26d3-de7d-45c1-b77e-b911b32a147b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment