Я пытаюсь создать страницу обновления профиля для кандидата, но на странице профиля html отображаются только имя пользователя и адрес электронной почты, а не другие атрибуты, плюс все формы, которые я создаю, не отображаются в html страница об отладке, но система не показывает наличие каких-либо ошибок. в чем может быть проблема
views.py
@login_required
def applicant(request):
if request.method == 'POST':
u_form = UserUpdateForm(request.POST, instance=request.user)
a_form = ApplicantUpdateForm(request.POST,
request.FILES,
instance=request.user.applicant)
if u_form.is_valid() and a_form.is_valid():
u_form.save()
a_form.save()
messages.success(request, f'Your account has been updated!')
return redirect('account')
else:
u_form = UserUpdateForm(instance=request.user)
a_form = ApplicantUpdateForm(instance=request.user.applicant)
context = {
'u_form': u_form,
'a_form': a_form
}
return render(request, 'users/account_settings.html', context)
forms.py
class UserUpdateForm(forms.ModelForm):
email = forms.EmailField()
class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email']
class ApplicantUpdateForm(forms.ModelForm):
class Meta:
model = Applicant
fields = ['mobilephone', 'maddress', 'country', 'homecity', 'citizenship', 'denomination', 'anyspouse',
модель профиля
class Applicant(models.Model):
user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
mobilephone = models.CharField(max_length=13)
maddress = models.TextField()
homecity = models.CharField(max_length=20)
citizenship = models.CharField(max_length=100)
country = models.CharField(max_length=100)
denomination = models.CharField(max_length=20)
anyspouse = models.BooleanField(default=False)
img = models.ImageField(default='default.jpg', upload_to='media')
def __str__(self):
return f'{self.user.username} Applicant'
Вот как выглядит страница, это единственное, что я вижу
urls.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from . import views
# from rest_framework import routers, serializers, viewsets
urlpatterns = [
path('', views.home, name='bugema-home'),
# path('form/', views.applicant_form, name="applicant_form"),
path('list/', views.applicant_list, name="applicant_list"),
path('register/', views.register, name="register"),
path('account/', views.accountSettings, name="account"),
path('login/', views.loginPage, name="login"),
path('logout/', views.logoutUser, name="logout"),
path('admin/', admin.site.urls),
# url(r'^api-auth/', include('rest_framework.urls'))
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
account_settings. html
{% extends 'applyBugema/base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<div class="media">
<img class="rounded-circle account-img" src="{{ user.applicant.image.url }}">
<div class="media-body">
<h2 class="account-heading">{{ user.username }}</h2>
<p class="text-secondary">{{ user.first_name }}</p>
<p class="text-secondary">{{ user.last_name }}</p>
<p class="text-secondary">{{ user.email }}</p>
<p class="text-secondary">{{ applicant.mobilephone }}</p>
<p class="text-secondary">{{ applicant.maddress }}</p>
<p class="text-secondary">{{ applicant.homecity }}</p>
<p class="text-secondary">{{ applicant.citizenship }}</p>
<p class="text-secondary">{{ applicant.country }}</p>
<p class="text-secondary">{{ applicant.denomination }}</p>
<p class="text-secondary">{{ applicant.anyspouse }}</p>
</div>
</div>
<!-- FORM HERE -->
<div class="content-section">
<fieldset class="form-group">
<legend class="border-bottom mb-4">
<p>Edit Details</p>
</legend>
<form method="POST" class="form-group" enctype="multipart/form-data">
{% csrf_token %}
{{ u_form|crispy }}
{{ a_form|crispy }}
</fieldset>
<div class="form-group">
<button type="submit" class="btn btn-outline-info">Continue to Apply...</button>
</div>
</form>
</div>