Django SQLite Database Configuration

Source: Internet
Author: User

A friend sent me a Django question a few days ago. Specifically:

May I ask the second chapter in the Django practice you gave me?
Refreshing your first Django Project
Step by step, follow his instructions. Because I encountered an error in the folder where Django was installed, I saw a folder on the same disk.
In Django-projects, the setting in setting is 'name': 'd: \ Django-project '.
Last run

Unable to open database file
. After reading the online statement, the write and read permissions for folders are modified, but the error is still the same.
I don't know why.
I used Django's last version 2.7.1. I don't know if I didn't bring SQLite at all?

Solution:
Error: Unable to open database file descriptionProgramFiles cannot be opened. There are two possible cases:
1. The program does not have the permission to open the folder where the database is located. If you are developing in windows, this problem does not exist.
2. The database path is incorrect.

This friend is developed in windows, so there is no first case. The error should be caused by incorrect database path settings.

Solution:

Import OS
DEBUG = true
Template_debug = debug

Site_path = OS. Path. dirname (OS. Path. abspath (_ file _) # The system path can be customized.

Admins = (
# ('Your name', 'Your _ email@domain.com '),
)

Managers = admins

Database_engine = 'sqlite3 '# 'postgresql _ psycopg2', 'postgresql ', 'mysql', 'sqlite3 'or 'oracle '.
Database_name = OS. Path. Join (site_path, 'guestbook. db') database files are placed in the root directory of the folder.

By the way, python uses the SQLite database by default.

We hope this example can help you avoid some mistakes.

Related Article

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.