mimeType error Django 1.9 Pinax-Referral

时间:2017-08-13 14:02:54

标签: python django

I am trying to run pinax referral app in my Django 1.9 project but get this error.

I have tried to change the mimeType to content_type in the views.py but nothing changed in the error.

Any ideas?

UPDATED error message

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'

from .models import Referral from .utils import 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"
    )

1 个答案:

答案 0 :(得分:0)

尝试通过此mimeType="application/json"

更改此行content_type="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"
)