인프런 커뮤니티 질문&답변
질문이 있습니다!
해결된 질문
작성
·
289
0
선생님의 강의를 보며 제가 만들어보고싶은 홈페이지를 구성하고 있습니다.
하지만 진행 중에 어려움이 있어 질문 드립니다.
*models.py
from django.db import models
from django.contrib.auth.models import User
class Story (models.Model):
title = models.CharField(max_length=20, verbose_name='주관기관')
image = models.ImageField(
upload_to='blog/%Y/%m/%d/', blank=True, verbose_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에 불러오질 못합니다.
모가 잘못된걸까요?ㅠㅠ
답변 6
0
0
SungYong Lee
지식공유자
지금 올려주신 urls.py를 보면, StoryList와 PostList가 같은 url로 지정되어 있습니다. 같은 url로 지정되어 있으니 위의 PostList를 이용하겠죠. 그래서 StoryList 클래스는 무시되고 있는 상태입니다.
0
woody
질문자
신경써서 답변주시니 너무 감사합니다ㅠㅠ
아직 제가 부족한게 많아서인지 선생님께서 말씀해주신 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
지식공유자
제가 똑같이 재현해봤는데, 저는 잘 됩니다. 다만 저는 post_list.html 이 아니라, story_list.html로 했습니다. 혹시 story_list.html을 만들어놓고, 아무것도 그 파일에 써놓지 않으신건 아닐까요?
그게 아니라면, urls.py에 문제가 있을 수도 있습니다. 그 파일은 올려주지 않으셨으니까요.
0
0





