Django Post 500 Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn django post 500 internal server error more about Stack Overflow the company Business Learn more about hiring developers or django 500 error log posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Django 500 Error Page
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up jQuery $.post to Django returns “500 Internal Server Error”
Django 500 Error Template
up vote 6 down vote favorite 1 I am working on the jQuery tutorial (Link) but have been stuck at the section, "RATE ME: USING AJAX" jQuery: $(document).ready(function() { // generate markup $("#rating").append("Please rate: "); for ( var i = 1; i <= 5; i++ ) $("#rating").append("" + i + " "); // add markup to container and apply click handlers to anchors $("#rating a").click(function(e){ // stop django return 500 error normal link click e.preventDefault(); // send request $.post("/vote", {rating: $(this).html()}, function(xml) { // format and output result $("#rating div").html( "Thanks for rating, current average: " + $("average", xml).text() + ", number of votes: " + $("count", xml).text() ); }); }); }); urls.py: urlpatterns = patterns('', (r'^rating/$', 'ajax_rating.views.rating'), (r'^vote/$', 'ajax_rating.views.vote'), ) views.py: @csrf_exempt def vote(request): if request.is_ajax(): rating = request['rating'] f = open('ratings.dat', 'w') votes = json.load(f) votes.append(rating) f.close() dict = {} total_rating = sum(votes) dict['count'] = len(votes) dict['avg'] = total_rating / dict['count'] return HttpResponse(serializers.serialize('xml', dict), 'application/xml') else: return HttpResponse(status=400) Basically, the html offers the user to make a choice between 1 to 5 (anchors with class=rating). Once a choice is clicked, the #rating div would get refreshed with the calculated result returned from the server. Problem: I am getting "HTTP 500 Internal Server Error" when I click on a choice. The error happens even before the request hits the view function, vote(request). I have tried to figure out why the error but don't have any clues. I don't think it has anything to do with csrf as I am using @csrf_exempt on the view function and have taken out 'django.middleware.csrf.CsrfViewMiddleware' from MIDDLEWARE_CLASSES. Please help~~ thanks to you experts django jquery share|improve this
here for a quick overview of the site Help Center Detailed answers to any questions you
Django Raise 500 Error
might have Meta Discuss the workings and policies of this site django ajax 500 error About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or django rest framework 500 error posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of http://stackoverflow.com/questions/5941528/jquery-post-to-django-returns-500-internal-server-error 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up HTTP 500 error on POST up vote 0 down vote favorite I am following instructions from here How can I login to django using tastypie to create a UserResource that can be used to login to http://stackoverflow.com/questions/17604214/http-500-error-on-post my django user. However, I am running into HTTP 500 error when I run the code. I tried to debug it myself, but could not figure it out. I am not sure how I can troubleshoot the 500 error. Any thought you can give is appreciated. Thanks!! My code is as below: #####api.py from registration.views import register from tastypie.resources import ModelResource from tastypie.constants import ALL from django.contrib.auth.models import User from django.contrib.auth import authenticate, login, logout from tastypie.http import HttpUnauthorized, HttpForbidden from django.conf.urls.defaults import url from tastypie.utils import trailing_slash class UserResource(ModelResource): class Meta: queryset = User.objects.all() fields = ['first_name', 'last_name', 'email'] allowed_methods = ['get', 'post'] resource_name = 'user' def prepend_urls(self): return [ url(r"^(?P
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss http://stackoverflow.com/questions/12015270/django-error-500-internal-server-error-when-doing-ajax-call the workings and policies of this site About Us Learn more about https://www.reddit.com/r/django/comments/366rkw/javascript_ajax_is_raising_500_error/ Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each 500 error other. Join them; it only takes a minute: Sign up Django: Error 500 (INTERNAL SERVER ERROR) when doing ajax call up vote 5 down vote favorite Hi when I'm doing ajax call, I'm getting this in console: POST http://127.0.0.1:8000/registration/check/username/ 500 (INTERNAL SERVER ERROR) Also when I click on this link, I'm getting this: DoesNotExist at /registration/check/username/ User matching django 500 error query does not exist. Request Method: POST Request URL: http://127.0.0.1:8000/registration/check/username/ Django Version: 1.3 Exception Type: DoesNotExist JQuery: function check_username() { $("#id_username").change(function() { var user = $("#id_username").val(); var status = $("#id_username").nextAll(".status").first().empty(); var checking = ' Checking availability...'; var success = ''; var e_length = '
User name have to be longer
'; if (user.length >= 3) { status.append(checking); $.ajax({ url: "/registration/check/username/", type: "POST", data: { username : $("#id_username").val() }, dataType: "text", success: function(msg) { if (msg == '1') { status.append(success); } else { status.append("This username is already in use"); } } }); } else if (user.length <= 3 && user.length != 0) { status.append(e_length); } else { status; } }); } Html: {% block main-menu %}