JS Regular
-test a regular expression that determines whether a string conforms to a rule
-exec to get matching data
Example of test:
From the above example we can see that if Rep.test match to return true, otherwise return false
Example of EXEC
The result of the above match is an array, but the first one is displayed no matter how many matches
Grouping in a regular
Global match
In the case of no grouping, it is taken from the first start, gets to the last one if fetched again, gets null, and then the first one starts.
If this is the case, use the grouping effect as follows:
Regular expressions
/.../for defining regular expressions
/.../g represents a global match
/.../i indicates case insensitive
/.. /m for multi-line matching
The multi-line match here needs to be noted:
By default, the regular match of JS is multi-line matching
Use the following example to understand the regular match after M plus
From the example can be seen only match to the first row of the content, the second row does not match, here is because the entire text is a string, so when the ^ with what start, is starting from the beginning of the string, so only to match to one, if this time want to match to more than one, the implementation method is through the M parameter
This is equivalent to matching each line as a string so that it matches the Java in the second row.
About the order in which events are executed
There are a lot of tags that have their own events, and we can give him permission again, so that will produce the order of the problem
The default event executes first:
CheckBox label
Custom events are executed first (most of them are custom event precedence):
A label submit tag
A validation of the order in which the checkbox events are executed
<! DOCTYPE html>
Analysis:
If the event that you define is executed first, then you should first print false and then be selected, but the print is true, so you can tell that the checkbox is the default event to execute first
ComponentBootStrap----Recommend this
Response type:
@media
code example:
<! DOCTYPE html>
From the effect can be seen
When the window is less than a certain value, it is displayed in red
Icon Text
@font-face
At the time of use a key place:
In CSS style, if you want a CSS style with the highest precedence, the example is as follows:
. c3{ border-radius:0!important; }
You can implement C3 CSS styles with the highest precedence, which are applied both above and below
The following two are in favor of background management
jQueryUI
Easyui
There are a number of similar plugins, such as the one that wants to achieve the effect of a carousel diagram:
You can implement it through Bxslider
The code is as follows:
<! DOCTYPE html>
Web FrameworkMVC framework:
Model View Controller
Database template file Business processing
Mtv:django is the MTV framework
Model Template View
Database template file Business processing
DjangoPIP2 Install Django
After installation.
The D:\python35\Scripts directory will have: Django-admin.exe
The following command creates a simple project
Ango-admin Startproject Project Name
Jango-admin Startproject MySite
A MySite directory is generated as follows:
Mysite-mysite -_init_.py -settings.py #配置文件 -urls.py #url对应关系 -wsgi.py #遵循WSGI规范, The actual use of uwsig+nginx-manage.py #管理Django规范 can be performed here: --python manage.py --python manage.py start xx --python manage.py makemigrations --python manage.py Migrate
Start the MySite created above
With Python manage.py Runserver can be started, here can also add parameter 127.0.0.1::8001 so that you can define the port to start, the boot process is as follows:
D:\mysite>python manage.py runserverperforming System checks ... System Check identified no issues (0 silenced). You have unapplied migration (s). Your project properly until you apply the Migrations for app (s): admin, Auth, contenttypes, sessions. Run ' python manage.py migrate ' to apply them. December, 2016-20:49:54django version 1.10.4, using Settings ' mysite.settings ' starting development Server at HTTP://1 27.0.0.1:8000/quit the server with Ctrl-break.
Then log in Http://127.0.0.1:8000/.
That means it's a success.
Create an App command
Python manage.py startapp app name
Python manage.py Startapp CMDB
Create a directory like
Add the following code to the views.py:
From django.shortcuts Import Httpresponsedef Home (Request): return HttpResponse ('
Also add the following in the MySite directory urls.py:
Urlpatterns = [ url (R ' ^admin/', admin.site.urls), url (r ' ^aa.html/', views.home),]
Log in like this
For an explanation of the app directory:
Migrations storing records when modifying table structure
admin.py Django provides us with back-office management
apps.py Configuring the current app
models.py ORM, writes the specified class by command to create a database structure
tests.py for unit Testing
views.py Business code
Write a simple exampleIn the views.py under the CMDB, write the following code:
From django.shortcuts import render def login (Request): return render (Request, ' login.html ')
Login.html put it under the templates.
The absolute path that is not filled here is already configured for the setting:
In the Mydjango directory urls.py write the following code:
From CMDB import viewsurlpatterns = [ url (R ' ^admin/', admin.site.urls), url (r ' ^login/', Views.login),] the entire directory is as follows:
The entire directory is as follows:
The login effect is as follows:
About the storage of static filesThis is the directory structure
Put CSS and JS in a static directory
The login.html code is as follows:
<! DOCTYPE html>
Configuration in the settings.py configuration file:
Static_url = '/static/' staticfiles_dirs= ( os.path.join (base_dir, ' static '),)
Gray is added to the background in CSS
It can be seen from the results that both JS and CSS are loaded successfully
Get information about a userThe code in views.py is as follows:
From django.shortcuts import renderfrom django.shortcuts import redirectdef Login (Request): print (Request.method) error_msg = "" if Request.method = = "POST": user = Request. Post.get ("User", None) pwd = Request. Post.get ("pwd", None) print (USER,PWD) if user = = "root" and pwd = = "123": return Redirect ('/HTTP/ Www.baidu.com ') else: error_msg= "username password Error" return render (Request, ' login.html ', {' error_msg ': error_ MSG})
The HTML code is as follows:
<! DOCTYPE html>
Red for the added content
This makes it possible to determine the input user and password.
When the account entered does not match the password:
If correct, it will jump to Baidu
The following is a complete exampleThe code in views.py is as follows:
From django.shortcuts import renderfrom django.shortcuts import redirectdef Login (Request): print (Request.method) ER Ror_msg = "" If Request.method = = "POST": User = Request. Post.get ("User", None) pwd = Request. Post.get ("pwd", None) print (user,pwd) if user = = "root" and pwd = = "123": Return redirect (' home ') else:error_msg= "Username password error" Return render (Request, ' login.html ', {' error_msg ': error_msg}) user_list =[ {"username": "Zhaofan", "gender": "Male", "email": "[email protected]",}, {"username": "Zhaoy", "gender": "Male", "email" : "[email protected]",}, {"username": "Zssan", "gender": "Female", "email": "[email protected]",}]def Home ( Request): if Request.method = = "POST": U = Request. Post.get (' username ') g = Request. Post.get (' gender ') e = Request. Post.get (' email ') Temp = temp = {"username": U, "gender": g, "email": E} user_list.append (temp) return render ( Request, ' home.html ', {' user_list ': user_lIST})
The code in urls.py is as follows:
From django.conf.urls import urlfrom django.contrib import adminfrom CMDB import viewsurlpatterns = [ url (r ' ^admin/'), admin.site.urls), url (r ' ^login ', views.login), url (r ' ^home ', views.home),]
The home.html code is as follows:
<! DOCTYPE html>The code for login.html is as follows:
<! DOCTYPE html>
The results of the operation are as follows:
Enter the correct user name and password to submit, jump to the home page
Here you can add new data:
Knowledge Point collation:Create a Django Project
Django-admin Startproject Project Name
Create an App
CD Project name
Python manage.py Startapp CMDB
static files
project.settings.py
Staticfiles_dirs = (
Os.path.join (Base_dir, "static"),
)
Template path
DIRS ==> [Os.path.join (Base_dir, ' templates '),]
In Settings
Middlerware
# Note CSRF
Defining Routing Rules
url.py
"Login"--Name of function
Defining View Functions
App under views.py
def func (Request):
# Request.method Get/post
# Http://127.0.0.1:8009/home?nid=123&name=alex
# request. Get.get (", None) # Gets the data sent by the request
# request. Post.get (", None)
# Return HttpResponse ("string")
# return render (Request, "Path to HTML template")
# return Redirect ('/can only be filled in URL ')
Template rendering
Special Template language
--{{variable name}}
def func (Request):
return render (Request, "index.html", {' Current_User ': "Alex"})
Index.html
..
<body>
<div>{{current_user}}</div>
</body>
====> generates the following string when rendered
..
<body>
<div>alex</div>
</body>
The For loop here is special:
{% for index in range (20)%}
.........
{%endfor%}
At the same time in the template language, there are beginning and ending
Indexes in the template language
def func (Request): return render (Request, "index.html", { ' current_user ': "Alex", ' user_list ': [' Alex ', ' Eric '], ' user_dict ': {' K1 ': ' v1 ', ' K2 ': ' V2 '}} ' index.html
Get content in the template language through {{User_list.1}}
JS Regular and web framework Django Introduction