inflearn logo
강의

講義

知識共有

PythonユーザーのためのWeb開発入門 A to Z Django + Bootstrap

질문이 있습니다!

解決済みの質問

322

woody

投稿した質問数 7

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에 불러오질 못합니다.

모가 잘못된걸까요?ㅠㅠ

python django bootstrap

回答 6

0

woody

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

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

woody

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

0

SungYong Lee

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

후속 강의

0

390

1

완성했습니다. 감사합니다

0

321

2

오늘 vps 에 domain 을 지정해주고 아직 활성화되지 않았는데

0

299

1

test 결과 두 가지 error 가 발생했습니다. 뭐가 잘못된 건지 도저히 모르겠습니다.

0

421

1

accounts/login 이 존재하지 않는다고 나옵니다

0

269

2

코드 질문입니다

0

248

1

포스트에 markdown을 사용해서 이미지를 추가할때

0

311

1

New Post 관련 질문드립니다.

0

179

1

이번 영상부터 각 포스트에 프리뷰 사진이 달라지셔서 질문 드립니다.

0

335

1

base 작업한 후 Category가 블로그 하단으로 내려갔습니다.

0

254

1

혹시 소스코드 전체가 담긴 주소를 좀 알 수 있을까요?

0

265

1

9분 경 테스트에서 Assretion Error가 발생합니다.

0

235

1

파이참 초기 설치 후 설정 관련해서 git에 항상 add되는 옵션을 체크했습니다.

0

345

3

F12를 눌러 console 창에서 오류를 확인할때 몇번째 줄인지 나오지 않습니다.

0

396

1

post view도 delete하려는데 막혀서 ㅠㅠ

0

197

1

"GET / HTTP/1.1" 400 143 그리고 "GET / HTTP/1.1" 404 2031

0

3304

3

연결이 안됩니다

0

506

8

서버에 연결하고 나면 그 후에 Cmder가 작동이 안되요

0

378

2

서버에 배포후 어드민계정

0

589

2

안녕하세요! 실서버에 올린 sqlite3의 데이터를 직접 확인하려면 어찌하나요?

0

2039

3

gitignore안먹히는현상

0

292

1

cmder 종료시 서버도 같이 종료됩니다.

0

220

1

' python manage.py makemigration blog ' 명령어 에러

0

588

2

python manage.py makemigrations 를 했을 때 오류가 납니다.

0

560

2