Django 500 Error Post
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 django 500 error log Learn more about Stack Overflow the company Business Learn more about hiring developers or
Django 500 Error Page
posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow
Django 500 Error Template
Community 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 Return 500 Error
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){ // django raise 500 error stop 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
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 more about Stack Overflow the company django ajax 500 error Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs django 500 error debug false Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, django 500 internal server error just like you, helping each other. Join them; it only takes a minute: Sign up Django return “ 500 INTERNAL SERVER ERROR” when $.post a utf-8 string up vote 3 down vote favorite I met a issue http://stackoverflow.com/questions/5941528/jquery-post-to-django-returns-500-internal-server-error that django always return "500 internal server error" when I tried to post a utf-8 string(e.g. Chinese string). But I tried to post a ascii string, it looks OK. Furthermore, It works OK on my own Archlinux machine, but it can't work on another CentOS server. How can I avoid this issue? template: $(".palcesubm").click(function(){ var location = $('#detail_address').val() $.post('/wechat/locate/select/create/', {'location':location}, function(){ window.location = "/wechat/locate/baidu/"; }) }); view: @csrf_exempt def create_location(request): if request.method == 'GET': http://stackoverflow.com/questions/26563222/django-return-500-internal-server-error-when-post-a-utf-8-string return render_to_response('create_location.html') else: print request.POST.get('location') request.session['location'] = request.POST.get('location') return HttpResponse('success') jquery django share|improve this question edited Oct 25 '14 at 14:40 Brandon 18.6k53466 asked Oct 25 '14 at 14:01 user1179442 15010 Can you turn on DEBUG and get the stacktrace for the error? –schillingt Oct 25 '14 at 14:58 I've trun on the DEBUG, but there is no error in the console. –user1179442 Oct 25 '14 at 15:18 does your print statement in the view get executed ? Also, sessions are not enabled by default. You need to activate the middleware in order to use it. Make sure you have it on.. docs.djangoproject.com/en/dev/topics/http/sessions/… –karthikr Oct 25 '14 at 15:27 Yes, I've enable the session in the middleware, and the [print] statement can't show on the console . But it is ok on my own machine. BTW, server and my machine share the same code –user1179442 Oct 25 '14 at 15:43 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted You're probably getting an UnicodeEncodeError because request.POST.get('location') returns an unicode object. When you try to print it, Python tries to encode it using the 'ascii' codec and fails because it contains non-ascii chars. If you really want to print it, use: print request.POST.get('location').encode('utf-8') EDIT: more info abo
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 Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack http://grokbase.com/t/gg/django-users/12556w8fky/ajax-call-says-networkerror-500-internal-server-error-http-127-0-0-1-8000-ajax 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 500 error each 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 django 500 error matching 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 %}