[英]Django admin /template/ folder missing after fresh install in virtualenv
嘗試轉到我的 Django 應用程序的管理面板時出現此錯誤:
TemplateDoesNotExist 位於 /admin/index.html
異常位置:/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py in find_template, line 139
Template-loader postmortem Django 嘗試按以下順序加載這些模板: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader: /home/mhb11/folder/project/templates/admin /index.html (文件不存在) /home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/bootstrap_pagination/templates/admin/index.html (文件不存在)
我有一個新的 Django 安裝,沒有移動任何文件,settings.py 在INSTALLED_APPS 中添加了django.contrib.admin
。
如果我轉到/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/contrib/admin/
我在那里找不到/templates/
文件夾(其中包含 index.html 和一堆其他文件)。
但是,安裝在不同機器上的完全相同的項目確實有/templates/
文件夾。 我在我的虛擬環境中卸載並重新安裝了 Django,但無濟於事。
settings.py 中已安裝的應用程序具有以下內容:
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', #'django.contrib.sessions', 'user_sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django.contrib.comments', 'myapp', 'myproject', 'south', 'registration', 'bootstrap_pagination', 'djcelery', 'tweepy', 'django.contrib.humanize', 'analytical', 'mathfilters', #'request', #'debug_toolbar', #'analytical', #'django_whoshere', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', )
我得到的錯誤的完整跟蹤是:
Internal Server Error: /admin/ Traceback (most recent call last): File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 140, in get_response
response = response.render() File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/response.py", line 105, in render
self.content = self.rendered_content File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/response.py", line 80, in rendered_content
template = self.resolve_template(self.template_name) File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/response.py", line 58, in resolve_template
return loader.get_template(template) File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/loader.py", line 146, in get_template
template, origin = find_template(template_name) File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/loader.py", line 139, in find_template
raise TemplateDoesNotExist(name) TemplateDoesNotExist: admin/index.html
你見過類似的東西嗎? 我該如何解決這個問題?
我不得不用pip
安裝一個舊的django 1.3
,我遇到了類似的問題。 django 應用程序中缺少templates
文件夾。
感謝@manu 對@shahz 回答的評論,我通過重新安裝解決了這個問題
pip install --no-binary django django==1.3.7
需要最新版本的pip
。 它可能會更新為
pip install --upgrade pip
我以前見過這個。 /templates/
不是您可能丟失的唯一文件夾。 請注意,您在/yourvirtualenv/django/
中放置了一個 django 文件夾,其中包含所有必需的文件夾。 為您解決問題的是通過以下 ubuntu 命令將文件(不覆蓋)從/yourvirtualenv/django/
/yourvirtualenv/local/lib/python2.7/site-packages/django/
到/yourvirtualenv/local/lib/python2.7/site-packages/django/
rsync -a -v --ignore-existing src dst
其中src
是/yourvirtualenv/django/
(即源), dst
是/yourvirtualenv/local/lib/python2.7/site-packages/django/
(即目標)。 接下來,再次啟動 Django admin,它應該可以工作了!
我不確定為什么會發生這種情況 - 有趣的是,這是 pip 在舊 Django 安裝中的行為不端。 如果我獲得有關它的新信息,我會更新此答案。 祝你好運!
使用pip
版本 20.2.4,它是:
pip install --no-binary :all: "django==1.3.7"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.