Error when using django.template

后端 未结 6 949
面向向阳花
面向向阳花 2021-01-31 05:02

I\'m a beginner in django and I got a lot of errors when using template module from django. The following works from the python shell:

from django import templat         


        
6条回答
  •  爱一瞬间的悲伤
    2021-01-31 05:22

    You can't access and run django projects from python shell. Django doesn't know what project you want to work on.

    You have to do one of these things:

    1. python manage.py shell
    2. Set DJANGO_SETTINGS_MODULE environment variable in your OS to mysite.settings
    3. Use setup_environ in the python interpreter:
       from django.core.management import setup_environ
       from mysite import settings
       setup_environ(settings)
    

    The first one is easiest and best method. Run your code in the django shell.

提交回复
热议问题