Let's create a simple website by django ...STEP01:Django-admin Startproject x01STEP02:CD x01 lsYou'll see ...Or you can use the tree:TreeSTEP03:Write the first view for your website ...CD X01vim views.pyWrite the below code into your new file (views.py from Import HttpResponse def Hello (Request): return HttpResponse ("HelloWorld")STEP04:Let the Django know y
This week listened to the teacher about the Django framework, the first time a more thorough understanding of the MTV framework. is also the first contact with the concept of the template, the study of a bit, now recorded good ...Let's start with a little bit about Django templates: Why do we use templates? I already knew that
LabelThe following sections provide an overview of common Django tags.If/elseThe {%if%} tag tests for a variable value, and if the result is true, the system will display everything between {%if%} and {%endif%}, see example:If Today_is_weekend%} {% endif%} is if today_is _weekend%} else%} {% endif%} {%if%} tags accept and,or,not to test for multivariable, refer to the following example:{%If Athlete_listand coach_list%} Both AthletesandCoa
, the default value is NoneWay One:From django.http import HttpResponseFrom django.template Import Loaderdef index (Request):# 1. Get the templateTemplate=loader.get_template (' index.html ')context={' city ': ' Beijing '}# 2. Render TemplateReturn HttpResponse (Template.render (context))Way Two (recommended):Render (Request object, template file path, template data dictionary)From django.shortcuts Import R
the Library instance, so that you can use the Django template language:
Register.filter (' Cut ', cut)
register.filter (' lower ', lower)
The Library.filter () method requires two parameters:
The name of the filter (a string)
Filter function itself
If you are using a Python 2.4 or newer version, you can use the adorner register.filter ():
@register. Filter (name= ' Cut
The style of one page on the website is always incorrect (the overall content is partial), and it is hard to find out that it is caused by the encoding of the template file.
The original did not pay attention to this problem, all the template files are saved as ANSI encoding, this ghost alone saved into the UTF-8, and which has Chinese, thus leading to this problem. I don't want to understand the specific
When you use Django for Web development, you often construct an underlying framework template called base.html, and then overload the common parts of the site and the definition blocks in its child templates.First create a base.html, the source code is:This template, called base.html, defines a simple HTML framework document, which we will use on the page in our
Django TemplateFor designers andProgramPersonnel provide different usageLet me first talk about the DesignIt consists of three parts:1 is the basic syntax, which is similar to the python syntax. If else for and so on. You can check the python control statements.If you are familiar with python, it should be easier to learn this.
2. Pipeline Symbol: If you want to change the object attributes. For example, intercepting characters. Remove the HTML forma
Django is PythonDevelopmentThe most commonly used technology in thehave been thinking about how to better organize lately.Djangostatic resources, such asJS,CSSOne , how do you write better code and structure with a front-end build tool? one of the first problems that needs to be addressed is the need toJsThe code is written in the template to get the variables passed in the background, such as: Div>H1>Testh
Templates are usually used to generate HTML, but Django templates can also generate any document based on text format.
The text enclosed in two braces (for example, {person_name}) is called a variable ).
The text enclosed by braces and percent signs (for example, {% if ordered_warranty %}) is a template tag ). Tags are clearly defined, that is, labels that only notify the
Django template is unavoidable to use some JS and CSS files, check a lot of pages, was made slightly dizzy, or the official website, to a link you can see their own English.https://docs.djangoproject.com/en/1.6/howto/static-files/The general steps are this:1. Make sure that the Installed_apps in the setting.py include Django.contrib.staticfiles, and no one can add it.2. Also add in setting.py, we need to ad
Static directory has CSS and JS and image folders, which put some static files of the site, static in the site root directory, Configuring static files in Django This is a matter of the Internet, and yesterday, when adding new content, found a problem, My URL If there are multiple "/" words (my is more than 3 such as:/A/B/C/D), the template calls to the static file will not be able to get references to s
Grappelli is the most star Django template system on GitHub
Http://django-grappelli.readthedocs.org/en/latest/quickstart.html#installation
The code is as follows:
Pip Install Django-grappellisettings.py
Installed_apps = (' Grappelli ',' Django.contrib.admin ',)
Add URL entry
The code is as follows:
Urlpatterns = Pa
Django template path settings: templates, TEMPLATE_DIRS, TEMPLATES,
Django version: 1.9.5
First, set templates to the same directory as manage. py, and then the template file under templates.
Then set settings. py: Pay attention to the modification of the yellow area.
TEMPLATES = [ { 'BACKEND': 'django.templa
When the following settings are set in settings. py:Template_loaders =('Django. template. loaders. filesystem. Loader','Django. template. loaders. app_directories.loader',)It means:Therefore, create a new templates/jobsfile under the Django project directory and put the. htm
The template can be completely replaced with a partial code after the new project is created.Create a app01 python startapp app01Create a static subdirectorysettings.py"" "Django Settings for User_manager project. Generated by ' Django-admin startproject ' using Django 2.0.1.For more information on the this file, Seeht
Where to modify:1, index.htmlDOCTYPE HTML>HTMLLang= "en">Head> MetaCharSet= "UTF-8"> title>Django Creates a fourth projecttitle>Head>Body> template variables are defined with variable names, such as: Name -Body>HTML>2. Modify the views.py file#Create your views here.#Coding:utf-8 fromDjango.httpImportHttpResponse#Import Libraries required to import the templates file fromDjango.templateImportLoader
Filter:1. built-in: Filter1.{{value|date: ' Y-m-d h:i:s '}}2 .....2. Custom Filter1. Create a new Templatetags (Python package) in the app2. Create a new py file with a name3. Internal definition An implementation provides specific function functions, which are registered in the Django template language in a fixed notation:From Django Import TemplateRegister =
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.