2013-10-15 1 views
0

this method으로 양식 출력을 사용자 정의하려고합니다. 예를 들면 : 나는 form.as_p 같은 양식을 렌더링하면 모든 것이 잘 작동하지만 필드를 렌더링사용자 정의 Django 양식이 저장되지 않음

<div class="fieldWrapper"> 
    {{ form.message.errors }} 
    <label for="id_message">Your message:</label> 
    {{ form.message }} 
</div> 

개별적으로 작동하지 않습니다.

필드를 숨기려면 각 필드를 개별적으로 렌더링하려고합니다. 숨기려고하는 필드에 모델 클래스의 null=True, blank=True 속성이 주어 지므로 필요하지 않습니다.

오류가 표시되지 않고 페이지가 새로 고쳐지고 데이터가 업데이트되지 않습니다. 나는이 요소들을 감안할 때 내가 누락 될 수있는 것이 무엇인지 확신 할 수 없다. 다음 뷰는 다음과 같습니다

뷰는 userena에서이다 : 나는 {% include 'my-template.html' %}를 사용하여 양식을 렌더링 할 HTML을 포함하고

@secure_required 
@permission_required_or_403('change_profile', (get_profile_model(), 'user__username', 'username')) 
def profile_edit(request, username, edit_profile_form=EditProfileForm, 
       template_name='userena/profile_form.html', success_url=None, 
       extra_context=None, **kwargs): 
""" 
Edit profile. 

Edits a profile selected by the supplied username. First checks 
permissions if the user is allowed to edit this profile, if denied will 
show a 404. When the profile is successfully edited will redirect to 
``success_url``. 

:param username: 
Username of the user which profile should be edited. 

:param edit_profile_form: 

Form that is used to edit the profile. The :func:`EditProfileForm.save` 
method of this form will be called when the form 
:func:`EditProfileForm.is_valid`. Defaults to :class:`EditProfileForm` 
from userena. 

:param template_name: 
String of the template that is used to render this view. Defaults to 
``userena/edit_profile_form.html``. 

:param success_url: 
Named URL which will be passed on to a django ``reverse`` function after 
the form is successfully saved. Defaults to the ``userena_detail`` url. 

:param extra_context: 
Dictionary containing variables that are passed on to the 
``template_name`` template. ``form`` key will always be the form used 
to edit the profile, and the ``profile`` key is always the edited 
profile. 

**Context** 

``form`` 
Form that is used to alter the profile. 

``profile`` 
Instance of the ``Profile`` that is edited. 
""" 
    user = get_object_or_404(get_user_model(), 
          username__iexact=username) 

    profile = user.get_profile() 

    user_initial = {'first_name': user.first_name, 
        'last_name': user.last_name} 

    form = edit_profile_form(instance=profile, initial=user_initial) 

    if request.method == 'POST': 
     form = edit_profile_form(request.POST, request.FILES, instance=profile, 
           initial=user_initial) 

     if form.is_valid(): 
      profile = form.save() 

      if userena_settings.USERENA_USE_MESSAGES: 
       messages.success(request, _('Your profile has been updated.'), 
           fail_silently=True) 

      if success_url: 
       # Send a signal that the profile has changed 
       userena_signals.profile_change.send(sender=None, 
                user=user) 
       redirect_to = success_url 
      else: redirect_to = reverse('userena_profile_detail', kwargs={'username': username}) 
      return redirect(redirect_to) 

    if not extra_context: extra_context = dict() 
    extra_context['form'] = form 
    extra_context['profile'] = profile 
    return ExtraContextTemplateView.as_view(template_name=template_name, 
              extra_context=extra_context)(request) 

. 프로필 개체를 업데이트하지 못하게 할 수 있습니까? 어떤 아이디어 주셔서 감사합니다!

+0

양식에서 제출을 클릭하면 서버 로그에는 무엇이 표시됩니까? – aychedee

답변

0

시도가 아닌 필드 오류가 있는지 확인하기 위해 템플릿 곳

 

{{ form.errors }} 

를 추가!

+0

니스 네가 맞았다 나는 들판을 놓 쳤어! 감사! –

+0

정확히 같은 문제가 한번 이상 발생했습니다 :) – Serafeim

관련 문제