2017-08-13 83 views
0

我想在我的Django 1.9项目中运行pinax推荐应用程序,但得到此错误。mimeType错误Django 1.9 Pinax-Referral

我试图在views.py中将mimeType更改为content_type,但错误中没有任何更改。

任何想法?

更新的误差信息

Django Version: 1.9 
Python Version: 2.7.10 


Traceback: 

File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response 
    149.      response = self.process_exception_by_middleware(e, request) 

File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response 
    147.      response = wrapped_callback(request, *callback_args, **callback_kwargs) 

File "/Library/Python/2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 
    23.     return view_func(request, *args, **kwargs) 

File "/Library/Python/2.7/site-packages/django/views/decorators/http.py" in inner 
    42.    return func(request, *args, **kwargs) 

File "/Library/Python/2.7/site-packages/pinax/referrals/views.py" in create_referral 
    50.   mimetype="application/json" 

File "/Library/Python/2.7/site-packages/django/http/response.py" in __init__ 
    283.   super(HttpResponse, self).__init__(*args, **kwargs) 

Exception Type: TypeError at /referrals/ 
Exception Value: __init__() got an unexpected keyword argument 'mimetype' 

从.models导入推荐 从.utils导入ensure_session_key

@login_required 
@require_POST 
def create_referral(request): 
    target = None 
    ctx = {"url": request.POST.get("redirect_to")} 

    if request.POST.get("obj_ct_pk") and request.POST.get("obj_pk"): 
     ct = ContentType.objects.get(pk=request.POST.get("obj_ct_pk")) 
     target = ct.get_object_for_this_type(pk=request.POST.get("obj_pk")) 
     ctx["obj"] = target 
     ctx["obj_ct"] = ct 

    referral = Referral.create(
     user=request.user, 
     redirect_to=request.POST.get("redirect_to"), 
     label=request.POST.get("label", ""), 
     target=target 
    ) 

    return HttpResponse(
     json.dumps({ 
      "url": referral.url, 
      "code": referral.code, 
      "html": render_to_string(
       "pinax/referrals/_create_referral_form.html", 
       ctx, 
       context_instance=RequestContext(request) 
      ) 
     }), 
     content_type="application/json" 
    ) 
+0

您可以在发送响应的位置添加代码吗?谢谢! –

+0

@MartinAlonso更新!谢谢 – 9minday

+0

@ 9minday为什么你不使用jsonresponse而不是httpresponse。它会为你节省一些代码 –

回答

0

尝试通过这一个content_type="application/json"

结果来改变这一行mimeType="application/json"

return HttpResponse(
    json.dumps({ 
     "url": referral.url, 
     "code": referral.code, 
     "html": render_to_string(
      "pinax/referrals/_create_referral_form.html", 
      ctx, 
      context_instance=RequestContext(request) 
     ) 
    }), 
    content_type="application/json" 
) 
+0

我改变了它,并更新了错误消息。仍然得到mimeType错误。感谢您的回答。更近了一步! :D – 9minday

+0

@ 9minday现在的错误信息是什么? –

+0

我更新了编辑中的错误信息:) – 9minday