我想在我的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"
)
您可以在發送響應的位置添加代碼嗎?謝謝! –
@MartinAlonso更新!謝謝 – 9minday
@ 9minday爲什麼你不使用jsonresponse而不是httpresponse。它會爲你節省一些代碼 –