Django's first App<2>__django

Source: Internet
Author: User
Tags postgresql sqlite sqlite database

Database Settings

Now, open the mystic/setting.py. It's a generic Python module with module-level variables that represent Django settings.

Django defaults to using the SQLite database. If you are unfamiliar with the database, or if you are just interested in trying to Django, this is the easiest choice. The SQLite database is contained in Python, so you don't need to install anything else to support your database. However, when you start your first project, you may want to use a more powerful database, such as PostgreSQL, to avoid the headaches of switching databases on future roads.

If you want to use a different database, install the appropriate database bindings and change the keys in databases ' default ' to match your database connection settings: engine-'django.db.backends.sqlite3 ' or 'django.db.backends.postgresql_psycopg2' or 'django.db.backends.mysql ' or ' Django.db.backends.oracle' name-the name of your database. If you use SQLite, the database will be a file on your computer; In that case, name should be an absolute path, including the filename. The default value Os.path.join (Base_dir, ' db.sqlite3 ') stores the files in your engineering directory.

If you are not using the SQLite database, additional settings, such as user,password,host, must be added:

DATABASES = {'
    default ': {
        ' ENGINE ': ' django.db.backends.postgresql_psycopg2 ', '
        NAME ': ' MyDatabase ',
        ' USER ': ' Mydatabaseuser ', '
        PASSWORD ': ' MyPassword ',
        ' HOST ': ' 127.0.0.1 ',
        ' PORT ': ' 5432 ',
    }
}

Note: If you are using PostgreSQL or MySQL, make sure that you have created the database at this time. Execute the CREATE DATABASE database_name in your DB interaction command. If you're using the SQLite database, you don't have to create anything, and the database files are created automatically.

When you edit mysite/setting.py, please set the Time_zone to your own time zone.

Also pay attention to installed_app this setting. This setting takes note of the names of all Django applications that can be used in many projects and can be packaged and propagated.

By default, Installed_app contains the following applications: Django.contrib.admin: A management website Django.contrib.auth: A validation system Django.contrib.contenttypes: A framework of content types Django.contrib.sessions: A session framework Django.contrib.messages: A message framework Django.contrib.staticfiles: A framework for managing static files

Some applications make the most of at least one database table, so create a datasheet in the database before using them. To do that, run the following command:

Python manage.py Migrate

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.