which template is best for django project code example
Example 1: how to get all template project in settinge use django
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
class InvalidTemplateVariable(str):
def __mod__(self,other):
from django.template.base import TemplateSyntaxError
raise TemplateSyntaxError("Invalid variable : '%s'" % other)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['%s/templates/' % (PROJECT_DIR),'%s/dev_templates/' % (PROJECT_DIR),],
'APP_DIRS': True,
'OPTIONS': {
'string_if_invalid': InvalidTemplateVariable("%s"),
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Example 2: django template examples
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{% block page_meta %}
{% endblock %}
{
{% block vendor_css %}
<link rel="stylesheet" type="text/css" media="all" href="{% static 'css/vendor.css' %}" />
{% endblock %}
{
{% block site_css %}
<link rel="stylesheet" type="text/css" media="all" href="{% static 'css/application.css' %}" />
{% endblock %}
{
{% autoescape off %}
{% block page_css %}{% endblock %}
{% endautoescape %}
{% block extra_head %}
{
{% endblock %}
<title>{% block page_title %}{% endblock %}</title>
</head>
<body class="{% block body_class %}{% endblock %}">
{% block body %}
{
{% endblock %}
{
{% block modals %}
{% endblock %}
{
{% block vendor_js %}
<script src="{% static 'js/vendor.js' %}"></script>
{% endblock %}
{
{% block site_js %}
<script src="{% static 'js/application.js' %}"></script>
{% endblock %}
{
<script type="text/javascript">
window._sharedData = {
{% autoescape off %}
{% block shared_data %}
'DEBUG': {% if debug %}true{% else %}false{% endif %},
{% endblock %}
{% endautoescape %}
}
</script>
{
{% autoescape off %}
{% block page_js %}
{% endblock %}
{% endautoescape %}
</body>
</html>