1
를 찾을 수 없습니다. 프로필 이미지가 업로드되면, profiles.views.py
에서이 기능이장고 나는 다음과 같은 파일 구조의 사이트가 이미지
{% extends "base.html" %}
{% load profiles_extras %}
{% block content %}
{% load staticfiles %}
<div class="container-fluid">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<!-- Store Information -->
<div class="col-lg-6">
<div class="panel panel-default">
<div class="panel-heading">
<h2>Store Information</h2>
</div>
<div class="center-block">
<!-- Change picture form -->
<form method="post" action="{% url 'update' %}" class="hidden form-inline" id="picture-change-form" enctype="multipart/form-data">
{% csrf_token %}
<div class="form-group">
<input type="file" class="form-control" name="picture" accept="image/*">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
{% if profile.logo %}
<img src="{{ profile.logo.url }}" class="img-responsive" id="logo" alt="Store Logo">
{% else %}
<img src="{% static 'no-image.png' %}" class="img-responsive" id="logo" alt="Store Logo">
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
라고 :
는urlpatterns = [
url(r'^profile/(?P<profile_id>[0-9]+)/$', views.Details, name = "account"),
url(r'^update/', views.Update_Profile, name = "update"),
] + static(settings.STATIC_URL, document_root = settings.STATIC_ROOT) +\
static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
템플릿 profile.html
은 다음과 같습니다 내 urls.py
에서 나는 다음과 같은 있습니다. 그러나
def update_logo(self, value):
self.logo = value
self.save()
내가 사진을 업로드 할 때, my_image.png
이 user_1/my_image.png
로 나타나고 파일이 발견되지 않았기 때문에 서버가 404을 반환
@login_required
def Update_Profile(request):
update_profile = Profile.objects.get(user = request.user)
has_updated = False
if ('picture' in request.FILES):
update_profile.update_logo(request.FILES['picture'])
return redirect('profiles.views.Details', profile_id = update_profile.id)
차례로이 기능은 update_logo
profiles.models.py
에서 호출 . 여기서 내가 뭘 잘못하고 있니?
나는 그것을 시도했지만 슬프게도 작동하지 않았다. 어떻게'/ user_1 /'을 정의 할 수 있습니까? – Woody1193
'MEDIA_URL'을'/ media /'로 변경하면'/ media/user_1 /'에서 업로드 된 이미지를 볼 수 있으며'/ user_1 /'url을 정의 할 필요가 없습니다. –
'Profile' 모델에서 모든 데이터를 삭제하려고 시도하십시오 –