Admin Site: TemplateDoesNotExist at /admin/

前端 未结 16 1780
鱼传尺愫
鱼传尺愫 2020-12-09 04:00

I\'m following Django\'s official Tutorial 2 but for some reason cannot create an admin site despite following all the steps correctly to my understanding.

This is t

相关标签:
16条回答
  • 2020-12-09 04:15
    for windows user the admin_tools in the templates section should be place in the begining
    
       'loaders': [
                **'admin_tools.template_loaders.Loader',**    
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
    
    0 讨论(0)
  • 2020-12-09 04:16

    I ran into the same problem, and I had to force pip to re-download django.

    pip install -r requirements.txt --ignore-installed --force-reinstall --upgrade --no-cache-dir
    

    Note: I know that the --no-cache-dir option is necessary, I'm not certain that the other options are all required.

    0 讨论(0)
  • 2020-12-09 04:19

    For my case, I have INSTALLED_APPS good, but just need to point inside TEMPLATE_DIRS the django admin template:

    import os #Put at the starting line
    
    PROJECT_DIR = os.path.dirname(__file__)
    
    TEMPLATE_DIRS = (
        ... #Another folder,
        os.path.join(PROJECT_DIR, 'relative/path/to/virtualenv/my_env/django/contrib/admin/templates'),
    )
    

    And it works

    0 讨论(0)
  • 2020-12-09 04:22

    This issue may happen if you changed something in TEMPLATES in settings.py:

    TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates')
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
               'django.template.context_processors.debug',
               'django.template.context_processors.request',
               'django.contrib.auth.context_processors.auth',
               'django.contrib.messages.context_processors.messages',
            ],
        },
    },]
    

    I have stumbled with this issue, alhamdulillah, my mistake was solved when I changed the 'APP_DIRS': False, to 'APP_DIRS': True,

    0 讨论(0)
  • 2020-12-09 04:23

    Since it works on other people's machines, and since you have the app directories loader enabled, admin site enabled in INSTALLED_APPS, and that's all it should take for templates to be discovered (I mean, what more can one do?) - I can only assume something is wrong with your django installation.

    This would be a good chance to start using virtualenvs and a fresh install of django to rule out your settings:

    Fire up a terminal, navigate to your project directory (doesn't actually matter...)

    pip install virtualenv # if you don't have it.
    
    virtualenv --no-site-packages env 
    # this creates a virtual python environment that doesn't include system packages
    
    source env/bin/activate
    # this forces your bash session to use that environment
    
    pip install django
    # installs a fresh copy of django to your new environment
    
    cd path_to_my_django_project    
    # now go to your site directory
    
    python manager.py runserver
    # visit admin site.
    
    0 讨论(0)
  • 2020-12-09 04:24

    I meet the same error, after several times pip install and uninstall Django, it's still not work. Then I download Django tar.gz file from Django website, and install from this file , all is fine. Hopefully this can help somebody.

    0 讨论(0)
提交回复
热议问题