を選択していない今のところすべてがここにしなさい助けと感謝私のフォームは、イメージファイル
は私model.pyある よく働くが、私は直面しています唯一の問題はimagefile..Imageフィールドをアップロードしているすると、選択した画像をインポートしません私のプロファイルフォームの
class UserProfile(models.Model):
user = models.OneToOneField(User,unique=True,on_delete=models.CASCADE)
bio = models.TextField(max_length=500,null=True,blank=True)
picture = models.ImageField(upload_to="profile_image",null=True)
company = models.CharField(max_length=500,null=True)
def __str__(self):
return self.user.username
# Sending a new signal when ever a user is created to create a new profile
@receiver(post_save,sender=User)
def create_profile(sender,instance,created,**kwargs):
if created:
UserProfile.objects.create(user=instance)
そしてここでは、ここに私のview.py
@login_required
@transaction.atomic
def update_profile(request):
if request.method == 'POST':
profile_form =
ProfileForm(request.POST,instance=request.user.userprofile)
if profile_form.is_valid():
profile_form.save()
messages.success(request,'Your Profile has been Updated')
return redirect('success:profile_account')
else:
messages.error(request,'fill out the fields correctly')
else:
profile_form = ProfileForm(instance=request.user.userprofile)
return render(request,"success/user_account/edit_profile.html",
{'profile_form':profile_form})
あるform.py
です210class ProfileForm(forms.ModelForm):
class Meta:
model= UserProfile
exclude=['user',]
fields =['bio','picture','company']
そしてここでは、私のアップデート
<h4>{{ user.get_username }}</h4>
<h4> {{ user.get_full_name}}</h4>
<h4> {{ user.first_name}}</h4>
<h4> {{ user.email}}</h4>
<h4> {{ user.bio}}</h4>
<h4> {{ user.userprofile.company }}</h4>SS
<h4>{{user.userprofile.bio}}</h4>
{% if user.userprofile.picture %}
<image src="{{user.userprofile.picture.url}}" width="40" height="40">
{% else %}
<p> Chose a profile</p>
{% endif %}
</image>
<a href="{% url 'success:Profile_update' %} ">Update</a>
</li>
そして、ここをレンダリングするHMTLファイルである私のEdit.htmlが
{%csrf_token%} {{profile_form.as_pを}ファイルであります}変更を保存する
問題は、画像がデータベースに保存されていないか、テンプレートに画像が表示されていませんか? – zaidfazil