我正在开发一个项目来自定义startproject
命令以从project_template创建django项目,见下文:
bootstrap/
├── __init__.py
├── conf
│ ├── __init__.py
│ └── project_template
│ ├── manage.py
│ ├── project_name
│ │ ├── __init__.py
│ │ ├── apps
│ │ │ ├── __init__.py
│ │ │ └── example
│ │ │ ├── __init__.py
│ │ │ ├── admin.py
│ │ │ ├── models.py
│ │ │ ├── tests.py
│ │ │ ├── urls.py
│ │ │ └── views.py
│ │ ├── contrib
│ │ │ └── __init__.py
│ │ ├── settings
│ │ │ ├── __init__.py
│ │ │ ├── base.py
│ │ │ ├── development.py
│ │ │ └── production.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── requirements
│ │ ├── base.txt
│ │ ├── development.txt
│ │ └── production.txt
│ ├── requirements.txt
│ ├── static
│ │ ├── js
│ │ │ └── base.js
│ │ ├── scss
│ │ │ └── base.scss
│ │ └── vendor
│ │ └── README
│ └── templates
│ ├── 404.html
│ ├── 500.html
│ ├── base.html
│ └── example
│ ├── base.html
│ └── index.html
└── management
├── __init__.py
└── commands
├── __init__.py
└── startproject.py
这是startproject.py
import os
import grabone as go
from django.core.management.commands.startproject import Command as StartprojectCommand
EXTENSIONS = ['py', 'txt', 'html', 'scss', 'css', 'js', 'bowerrc', 'rst']
class Command(StartprojectCommand):
def handle(self, project_name=None, target=None, *args, **options):
options['extensions'] += EXTENSIONS
return StartprojectCommand.handle(self, project_name=project_name, target=target, *args, **options)
def handle_template(self, template, subdir):
if template is None:
return os.path.join(go.__path__[0], 'conf', subdir)
return StartprojectCommand.handle_template(self, template, subdir)
当我运行django-admin startproject test1
时,它会创建项目文件夹等,但它会尝试解析html模板并给我一个错误:
django.template.base.TemplateSyntaxError: 'staticfiles' is not a valid tag library: Template library staticfiles not found, tried django.templatetags.staticfiles
这就是模板的样子:
{% load staticfiles %}
<html>
...
</html>
这就是设置中INSTALLED_APPS的样子:
DJANGO_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
)
THIRD_PARTY_APPS = (
'django_extensions',
'pipeline',
# Add third party apps here
)
LOCAL_APPS = (
# Add local apps here
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
虽然设置中的内容没有被执行......
答案 0 :(得分:0)
从
中删除了html
EXTENSIONS = ['py', 'txt', 'html', 'scss', 'css', 'js', 'bowerrc', 'rst']
的工作。