swsnu / swppfall2018

22 stars 21 forks source link

HW3 model test 관련 질문입니다. #122

Open Evan-JH-Kim opened 5 years ago

Evan-JH-Kim commented 5 years ago

from .models import Article, Comment from django.contrib.auth.models import User

new_user = User.objects.create_user(username='swpp', password='iluvswpp') # Django default user model new_article = Article(title='I Love SWPP!', content='Believe it or not', author=new_user) new_article.save() new_comment = Comment(article=new_article, content='Comment!', author=new_user) new_comment.save()

Model을 올바르게 생성했는지 테스트하는 코드를 blog 디렉토리에서 실행시키니 첫 두 줄에서 error가 발생합니다.

from .models import Article, Comment의 경우 ModuleNotFoundError: No module named '__main_.models'; '__main_\' is not a package가 발생하며

from django.contrib.auth.models import User의 경우 django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. 가 발생합니다.

이 경우 어떻게 해결하여야 하나요?

sanha commented 5 years ago

skeleton directory에서 python manage.py shell 으로 shell을 띄워 코드를 실행시켜보시겠어요? (models에 대한 import는 이 경우 blog.models로 바꾸셔야 할 것 같습니다.)