3
50 시간 전부터 장고와 파이썬을 시작했는데 쉽게 들릴 수 있습니다.Django 사용자와의 오류 : "AttributeError : 'User'객체에 'get'속성이 없습니다."
내 프로젝트에서 비슷한 양식 구현을 사용하여 문제가없는 비슷한 '만들기'보기를 사용하고 있습니다. 이 경우 위에서 언급 한 오류가 발생합니다.
내가 Pinax을 사용하고... 당신의 views.py
당신이 LocationForm
의 인스턴스에 첫 번째 매개 변수로 request.user
을 전달하는 라인 (23)에
2 from django.shortcuts import render_to_response, get_object_or_404
3 from django.template import RequestContext
4 from django.http import HttpResponseRedirect
5 from django.core.urlresolvers import reverse
6 from django.contrib.auth.models import User
7 from django.contrib.auth.decorators import login_required
8 from django.utils.translation import ugettext_lazy as _
9
10 from django.conf import settings
11
12 if "notification" in settings.INSTALLED_APPS:
13 from notification import models as notification
14 else:
15 notification = None
16
17 from location.models import Location
18 from location.forms import LocationForm, LocationUpdateForm
19
20
21 @login_required
22 def create(request, form_class=LocationForm, template_name="location/create.html"):
23 location_form = form_class(request.user, request.POST or None)
24
25
26
27 if location_form.is_valid():
28 location = location_form.save(commit=False)
29 location.creator = request.user
30 location.save()
31 return HttpResponseRedirect(location.get_absolute_url())
32
33 return render_to_response(template_name, {
34 "location_form": location_form,
35 }, context_instance=RequestContext(request))
Traceback (most recent call last):
File "/Users/philgo20/code/LeadMiner/django/core/servers/basehttp.py", line 636, in __call__
File "/Users/philgo20/code/LeadMiner/django/core/handlers/wsgi.py", line 241, in __call__
File "/Users/philgo20/code/LeadMiner/django/core/handlers/base.py", line 134, in get_response
File "/Users/philgo20/code/LeadMiner/django/core/handlers/base.py", line 154, in handle_uncaught_exception
File "/Users/philgo20/code/LeadMiner/django/core/handlers/base.py", line 92, in get_response
File "/Users/philgo20/python/django/trunk/django/contrib/auth/decorators.py", line 78, in __call__
return self.view_func(request, *args, **kwargs)
File "/Users/philgo20/code/jezam_kms/apps/location/views.py", line 27, in create
if location_form.is_valid():
File "/Users/philgo20/code/LeadMiner/django/forms/forms.py", line 120, in is_valid
File "/Users/philgo20/code/LeadMiner/django/forms/forms.py", line 111, in _get_errors
File "/Users/philgo20/code/LeadMiner/django/forms/forms.py", line 234, in full_clean
File "/Users/philgo20/code/LeadMiner/django/forms/widgets.py", line 170, in value_from_datadict
AttributeError: 'User' object has no attribute 'get'
그걸 지우지 않았습니까? 이봐. 감사 ;-) – philgo20