Django learning (1)

1. Create a project django: django-admin startproject testproject

2. Create Application: After entering testproject directory, enter the command python manage.py startapp test1 to create

3. Initial Data: python manage.py migrate

4. Start: python manage.py runserver 127.0.0.1:8080

5. Access 127.0.0.1:8080

 

In django, path () function describes four parameters:

1.route: URL of a criterion match route. When django response to a request, it will start from the first urlpatterns, according to the order of the list of matches, know where to find the matching entry. At the same time, these guidelines will not match GET and POST parameters, or the domain name.

2.view: When django find a matching criterion, it will call this particular view function, passing a HttpRequset object as the first argument, the "capture" of the parameters passed in the form of keyword arguments.

3.kwargs: any number of keyword arguments passed to the target view as a function of a dictionary.

4.name: your only reference it anywhere django URL for your name to make, especially in the template. This useful feature allows you to change just one file will be able to modify a global URL pattern.

 

django default database is SQLite, if you want to change the database used by django, need to be modified in the setting.py DATABASES attributes:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'testdemo',
        'USER': 'root',
        'PASSWORD':'',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

Then enter python manage.py migrate will initialize the database, but now need mysql, create a good database.

Guess you like

Origin www.cnblogs.com/BigXu/p/11278043.html