2016-08-07 3 views
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.pnguser_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_logoprofiles.models.py에서 호출 . 여기서 내가 뭘 잘못하고 있니?

답변

1

장고에는 /profile/, /update/, /static//에 대한 URL이 정의되어 있습니다.

URL /user_1/은 정의되지 않습니다.

MEDIA_URL/media/으로 변경하십시오.

+0

나는 그것을 시도했지만 슬프게도 작동하지 않았다. 어떻게'/ user_1 /'을 정의 할 수 있습니까? – Woody1193

+0

'MEDIA_URL'을'/ media /'로 변경하면'/ media/user_1 /'에서 업로드 된 이미지를 볼 수 있으며'/ user_1 /'url을 정의 할 필요가 없습니다. –

+0

'Profile' 모델에서 모든 데이터를 삭제하려고 시도하십시오 –

관련 문제