tag 모델 만들기 강의에서 오류가났는데 어디서 잘못된건지 모르겠네요
848
작성한 질문수 71
오류가 어디서 잘못된건지 모르겠네요
다시 처음부터하는거 힘든데 하나 하나 풀어나가는데 좋겠는데요
다 고쳐야 하는데요
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Program Files\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\apps\registry.py", line 122, in populate
app_config.ready()
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\contrib\admin\apps.py", line 27, in ready
self.module.autodiscover()
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\contrib\admin\__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\github\-do_it_django_inflearn_2024-\venv\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Program Files\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\github\-do_it_django_inflearn_2024-\blog\admin.py", line 2, in <module>
from .models import Post, Category
ImportError: cannot import name 'Post' from 'blog.models' (C:\github\-do_it_django_inflearn_2024-\blog\models.py)
답변 3
0
다른 오류가 생겼는데요
python manage.py makemigrations 치면
빨간 글씨가 나오네요
이렇게 떠요
SystemCheckError: System check identified some issues:
ERRORS:
blog.Post.head_image: (fields.E202) ImageField's 'upload_to' argument must be a relative path, not an absolute path.
HINT: Remove the leading slash.
0
경로를 잘못 적으셨습니다. 같은 주소로 써야 하는데, 하나는 슬래시를 포함해서 시작하고, 하나는 없는 상태로 쓰셨네요. head_image의 경로가 잘못되었습니다.
head_image = models.ImageField(upload_to='/blog/images/%Y/%m/%d/', blank=True)
file_upload = models.FileField(upload_to='blog/files/%Y/%m/%d/', blank=True)
0
models.py 파일에서 코드 보여줄께요
이렇게 작성했는데 안되네요
from django.db import models
from django.contrib.auth.models import User
import os
class Category(models.Model):
name = models.CharField(max_length=50, unique=True)
slug = models.slugField(max_length=200, unique=True, allow_unicode=True)
def __str__(self):
return self.name
def get_absolute_url(self):
return f'/blog/category/{self.slug}/'
class Meta:
verbosr_name_plural = 'Categories'
class Tag(models.Model):
name = models.CharField(max_length=50, unique=True)
slug = models.slugField(max_length=200, unique=True, allow_unicode=True)
def __str__(self):
return self.name
def get_absolute_url(self):
return f'/blog/tag/{self.slug}/'
class Post(models.Model):
title = models.CharField(max_length=50)
hook_text = models.CharField(max_length=100, blank=True)
content = models.TextField()
head_image = models.ImageField(upload_to='/blog/images/%Y/%m/%d/', blank=True)
file_upload = models.FileField(upload_to='blog/files/%Y/%m/%d/', blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
author = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
category = models.ForeignKey(Category, null=True, blank=True, on_delete=models.SET_NULL)
tag = models.ManyToManyField(Tag, null=True, blank=True)
def __str__(self):
return f'[{self.pk}] {self.title} :: {self.author}'
def get_absolute_url(self):
return f'/blog{self.pk}/'
def get_file_name(self):
return os.path.basename(self.file_upload.name)
def get_file_ext(self):
return self.get_file_name().split('.')[-1]
0
class Tag가 Category class 안에 들어가 있는거 아닌가요?
Tag 클래스도 카테고리와 포스트 클래스처럼 가장 왼편으로 붙여야 될 것 같은데요..
로그인 오류
0
87
2
docker-compose down 안되는 현상
0
204
2
url pattern관련 문의
0
198
2
오류
0
255
1
doitdjango 블로그 게시판 작동 오류
1
300
1
구글 로그인 오류 .
0
463
2
makemigrations 을 했는데 aws lightsail에서
0
205
1
안녕하세요 강사님,
0
403
2
맥북 프로 14 가상화 확인
0
438
2
테스트 코드 오류
0
389
2
섹션 6-2 알림 내용 중 링크가 잘못되어 있네요.
0
282
2
장고 개발 준비.
0
407
2
Mac
0
321
1
TDD 통과 했지만, 실제 웹에서 작동하지 않습니다.
0
375
1
summernote를 적용하고 이미지를 업로그하면 모바일에서 볼때는 이미지가 크게 나오는데 어떻게 해야 되나요?
0
916
2
python manage.py test 를 돌리면 allauth.socialaccount.models.SocialApp.DoesNotExist 에러가 뜹니다.
1
1696
2
self.client.post에 글이 생성되지않습니다
0
339
1
Nginx 설정 이후 개발용 도커 컨테이너 실행
0
552
1
UpdateView - 포스트 수정 페이지 만들기 에서 질문이 있습니다.
0
405
1
from .models import Question
0
1220
1
파이참 장고 인식 불가 문제
0
1006
2
배포용 도커 컨테이너 실행이 안됩니다
0
717
1
docker-compose exec web manage.py migrate
0
555
1
search_info가 안나옵니다..
0
360
2





