작성
·
806
0
오류가 어디서 잘못된건지 모르겠네요
다시 처음부터하는거 힘든데 하나 하나 풀어나가는데 좋겠는데요
다 고쳐야 하는데요
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
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
경로를 잘못 적으셨습니다. 같은 주소로 써야 하는데, 하나는 슬래시를 포함해서 시작하고, 하나는 없는 상태로 쓰셨네요. head_image의 경로가 잘못되었습니다.