강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của woodybymaycan
woodybymaycan

câu hỏi đã được viết

Giới thiệu về phát triển web cho người dùng Python từ A đến Z Django + Bootstrap

질문이 있습니다!

Đã giải quyết

Viết

·

306

0

선생님의 강의를 보며 제가 만들어보고싶은 홈페이지를 구성하고 있습니다.

하지만 진행 중에 어려움이 있어 질문 드립니다.

*models.py

from django.db import models
from django.contrib.auth.models import User
class Story (models.Model):
    title = models.CharField(max_length=20verbose_name='주관기관')
    image = models.ImageField(
        upload_to='blog/%Y/%m/%d/'blank=Trueverbose_name='이미지')
    video_link = models.URLField(verbose_name='링크')

    def __str__(self):
        return '{}'.format(self.title)

*views.py

from django.shortcuts import render
from .models import Post, Category, Tag, Story
from django.views.generic import ListView
class StoryList(ListView):

    model = Story

    def get_context_data(self, *, object_list=None, **kwargs):
        context = super(type(self), self).get_context_data(**kwargs)
        context['story_list'] = Story.objects.all()

        return context

*post_list.html

{% for story in story_list %}
<div class="storycircle clearfix">
<div class="circle">
<div class="symbol">
<figure>
<a class="venobox" data-autoplay="true" data-vbtype="video" data-title="title"  
href="{{ story.video_link }}" data-gall="myGallery"><img src="{{ story.image.url }}" 
alt="{{ story.title }}"></a>
</figure>
</div>
<div class="name">
<h4>{{ story.title }}</h4>
</div>
</div>
</div>
{% endfor %}

위와 같이 코드를 구성한 결과 admin 페이지에서 정상적으로 작동되는데

html에 불러오질 못합니다.

모가 잘못된걸까요?ㅠㅠ

pythondjangobootstrap

Câu trả lời 6

0

woody님의 프로필 이미지
woody
Người đặt câu hỏi

오 문제가 해결됬어요!!!!
이해했습니다 정말 감사합니다!! 

0

SungYong Lee님의 프로필 이미지
SungYong Lee
Người chia sẻ kiến thức

지금 올려주신 urls.py를 보면, StoryList와 PostList가 같은 url로 지정되어 있습니다. 같은 url로 지정되어 있으니 위의 PostList를 이용하겠죠. 그래서 StoryList 클래스는 무시되고 있는 상태입니다. 

0

woody님의 프로필 이미지
woody
Người đặt câu hỏi

신경써서 답변주시니 너무 감사합니다ㅠㅠ

아직 제가 부족한게 많아서인지 선생님께서 말씀해주신 post_list.html을 story_list.html로 했다는게 이해가 가지 않습니다.ㅠㅠ

tamplete / blog 안에 있는 post_list.html 파일을 story.html 파일로 제목을 바꾸셨다는 건가요?

아직도 문제가 해결되지 않아 아래 urls.py를 첨부합니다!

*urls.py

from django.contrib import admin
from django.urls import path, include
from . import views


urlpatterns = [
    path('tag/<str:slug>/', views.PostListByTag.as_view()),
    path('category/<str:slug>/', views.PostListByCategory.as_view()),
    path('', views.PostList.as_view()),
    path('', views.StoryList.as_view()),

]

0

SungYong Lee님의 프로필 이미지
SungYong Lee
Người chia sẻ kiến thức

제가 똑같이 재현해봤는데, 저는 잘 됩니다. 다만 저는 post_list.html 이 아니라, story_list.html로 했습니다. 혹시 story_list.html을 만들어놓고, 아무것도 그 파일에 써놓지 않으신건 아닐까요?

그게 아니라면, urls.py에 문제가 있을 수도 있습니다. 그 파일은 올려주지 않으셨으니까요. 

0

woody님의 프로필 이미지
woody
Người đặt câu hỏi

네 에러메시지도 안뜨고 html에 출력되지않고 저 해당 구역이 그냥 빈 상태로 나옵니다

0

SungYong Lee님의 프로필 이미지
SungYong Lee
Người chia sẻ kiến thức

html에 불러오지 못한다는 이야기는 에러메세지도 브라우저에 출력되지 않고 하얀 화면만 나온다는 뜻인가요?

Hình ảnh hồ sơ của woodybymaycan
woodybymaycan

câu hỏi đã được viết

Đặt câu hỏi