我将Django web application
部署到我的新服务器中以设置生产应用程序。
2天后,为了配置Apache2
和wsgi
,我根据静态文件和管理静态页面获取了新问题。
DatasystemsCORE
├── DatasystemsCORE
│ ├── settings.py
├── API-GED
├── Authentification
├── Configuration
├── Templates
├── static
│ ├── Theme
│ ├── Theme1
│ ├── css
│ ├── js
│ ├── images
│ ├── flags
│ ├── Theme2
│ ├── css
│ ├── js
│ ├── images
│ ├── flags
├── ...
如您所见,我有一个静态目录,其中包含选择主题功能的所有静态文件。
我必须根据我的静态目录中的“管理”部分来制作:python3 manage.py collectstatic
以导入静态文件。
# Static files (CSS, JavaScript, Images)
# http://docs.djangoproject.com/en/2.0.1/howto/static-files/
STATIC_URL = '/static/'
THEME_DIRS = os.path.join(BASE_DIR, "static", "Theme/")
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static"), THEME_DIRS, ]
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
Copying '/var/www/html/DatasystemsCORE/static/Theme/Datasystems/css/Base.css'
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 189, in handle
collected = self.collect()
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
handler(path, prefixed_path, storage)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 354, in copy_file
self.storage.save(prefixed_path, source_file)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/core/files/storage.py", line 49, in save
return self._save(name, content)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/core/files/storage.py", line 236, in _save
os.makedirs(directory)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/os.py", line 231, in makedirs
makedirs(head, mode, exist_ok)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/os.py", line 231, in makedirs
makedirs(head, mode, exist_ok)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/os.py", line 231, in makedirs
makedirs(head, mode, exist_ok)
File "/home/valentin/.virtualenvs/DSCoreEnv/lib/python3.5/os.py", line 241, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/var/www/html/DatasystemsCORE/DatasystemsCORE/static'
我不明白为什么Django在我现有的静态目录之外创建静态目录?为什么我被拒绝了?
如何将Admin静态元素导入静态目录?
我假设来自此路径的静态文件:.virtualenvs/DSCoreEnv/lib/python3.5/site-packages/django/contrib/admin/static/admin/
答案 0 :(得分:0)
我根据Alasdair的答案发布了这个答案,他帮助我解决了我的问题。
我没有克服收集静态文件,因为我的目录在我的Django Web项目中。这是一个错误,我在我的Django项目之外创建了一个新目录。
我在settings.py文件中指定了路径。然后,我执行了这个命令:
python manage.py collectstatic
实际上,所有静态文件都在我的ne目录中,在Django Project之外,它运行正常!