Minsub Yoon
@msra9my63604
Reviews Written
-
Average Rating
-
Posts
Q&A
request.user๊ฐ SimpleLazyObject๋ฅผ ๋ฐํํฉ๋๋ค.
๊ฐ์ข ๋ท๋ถ๋ถ์ ๋ณด๊ณ ํด๊ฒฐ๋ฌ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค.
- 0
- 2
- 552
Q&A
์์ฑ ๋ฐ ์์ ํ์ด์ง ์ฌ์ฉ์ 302 ์๋ฌ
์คํ๊ฐ ์๋ ์ค ์์๋๋ฐ form์ enctype="multipart/form-data" ๋ฅผ ์ฐ์ง ์์์ ์ด๋ฏธ์ง๊ฐ ๋ณ๊ฒฝ๋์ง ์๋๊ฑฐ์๋๊ฑฐ ๊ฐ์ต๋๋ค. enctype ์ ๋ ฅํ๋๋ ํด๊ฒฐ๋ฌ์ต๋๋ค!
- 0
- 2
- 1.3K
Q&A
์นดํ ๊ณ ๋ฆฌ์ slug๋ฅผ ์์ ํ๋ฉด 301์๋ฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ ์๋ ๋ง์์ด ๋ง๋ค์.. ์ฌ๋์๋ฅผ ์ถ๊ฐํ๋๋ ํด๊ฒฐ๋ฌ์ต๋๋ค. ์ด๊ฒ๋๋ฌธ์ ์ดํ๋ด๋ด ๋๋๋๋๋ฐ.. ํด๊ฒฐ๋์ ์์ด ์์ํ๋ค์. ์ ๋ง ๊ฐ์ฌํฉ๋๋ค!
- 0
- 4
- 420
Q&A
์นดํ ๊ณ ๋ฆฌ์ slug๋ฅผ ์์ ํ๋ฉด 301์๋ฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
ํ ์คํธ์ฝ๋๋ def test_post_list_by_category(self): # ์นดํ ๊ณ ๋ฆฌ๋ฅผ ์์ฑํ๋ค. category_politics = create_category(name='์ ์น/์ฌํ') self.assertGreater(Category.objects.count(), 0) # ํฌ์คํธ๋ฅผ ์์ฑํ๋ค. post_000 = create_post( title='the first post', content='hello world', author=self.author_000 ) post_001 = create_post( title='the second post', content='goodbye world', author=self.author_000, category=category_politics ) self.assertGreater(Post.objects.count(), 0) # /blog/category/slug/์ ์ ๊ทผ์ ์๋ํ๊ณ ์ฑ๊ณต์ฌ๋ถ๋ฅผ ํ์ธํ๋ค. response = self.client.get(category_politics.get_absolute_url()) self.assertEqual(response.status_code, 200) soup = BeautifulSoup(response.content, 'html.parser') # ํ์ด์ง ํ์ดํ ํ๊ทธ๋ฅผ ํ์ธํ๋ค. self.assertEqual(soup.title.text, 'Blog - {}'.format(category_politics.name)) # ๋ค๋น๊ฒ์ด์ ์ Blog, About Me๊ฐ ์๋์ง ํ์ธํ๋ค. self.check_navbar(soup) # ๋ฏธ๋ถ๋ฅ ๋ฑ์ง๋ ์๊ณ , ์ ์น/์ฌํ ๋ฑ์ง๋ง ์๋์ง ํ์ธํ๋ค. main_div = soup.body.find('div', id='main_div') self.assertNotIn('๋ฏธ๋ถ๋ฅ', main_div.text) self.assertIn(category_politics.name, main_div.text) views.py๋ class PostList(ListView): model = Post def get_queryset(self): return Post.objects.order_by('-created') def get_context_data(self, *, object_list=None, **kwargs): context = super(PostList, self).get_context_data(**kwargs) context['category_list'] = Category.objects.all() context['posts_without_category'] = Post.objects.filter(category=None).count() return contextclass PostDetail(DetailView): model = Post def get_context_data(self, *, object_list=None, **kwargs): context = super(PostDetail, self).get_context_data(**kwargs) context['category_list'] = Category.objects.all() context['posts_without_category'] = Post.objects.filter(category=None).count() return contextclass PostListByCategory(PostList): def get_queryset(self): slug = self.kwargs['slug'] category = Category.objects.get(slug=slug) return Post.objects.filter(category=category).order_by('-created') blog/urls.py๋ from django.urls import pathfrom . import viewsurlpatterns = [ path('category//', views.PostListByCategory.as_view()), path('/', views.PostDetail.as_view()), path('', views.PostList.as_view())] ์ ๋๋ค.
- 0
- 4
- 420
Q&A
๋ค๋๋ค ๊ด๊ณ์ ๋ฐ์ดํฐ ๋ก๋ฉ ๊ด๋ จ ์ง๋ฌธ
attributes: ['id']๋ฅผ ํด๋ User ํ ์ด๋ธ์ ๋ค๋ฅธ ํ๋กํผํฐ๋ง ์ ๊ฑฐ๋๊ณ Like ๊ฐ์ฒด๋ ๊ณ์ ๋์ต๋๋ค. ๋ญ๊ฐ ์์ธ์ธ์ง ๋ชจ๋ฅด๊ฒ ๋ค์..
- 1
- 3
- 218
Q&A
๋ก๊ทธ์ธ ์ ๋ณด ๋ก๋ฉ ๊ด๋ จ ์ง๋ฌธ
ํ์ด์ง๋ง๋ค LOAD_USER_REQUEST ์ก์ ์ ๋์คํจ์นํด์ผํ๋๊ตฐ์. ๊ฐ์ฌํฉ๋๋ค.
- 1
- 2
- 241
Q&A
๋ฉ์ธํฌ์คํธ ๋ก๋ฉ ๊ด๋ จ ์ง๋ฌธ
๊ฐ์ฌํฉ๋๋ค. ํด๊ฒฐ๋ฌ์ต๋๋ค. ๋ฆฌ๋์์ ํํ๊ฐ ์ผ์ ํจํด์ ๋ฐ๋ฅด๋ค๋ณด๋ if๋ฅผ ์ธ ์๊ฐ์ ๋ชปํด๋ดค๋ค์..ใ ใ ..
- 0
- 3
- 250
Q&A
์ด๋ฏธ์ง ์ ๋ก๋ -> ์ทจ์ -> ์ ๋ก๋ ๊ด๋ จ ์ง๋ฌธ
๊ฐ์ฌํฉ๋๋ค. ํด๊ฒฐ๋ฌ์ด์!
- 1
- 2
- 359




