My first Django Project-<django + MySQL + ajax> (1)

Source: Internet
Author: User
Tags lowercase

Since some of the recent work has some information that takes extra time to collect, there are now relevant operations to record the status every day, but there is no good state-gathering tool to collect the state, so in many cases we don't know whether the state is getting better or getting worse. If you use Excel to assist with logging, it can cause a lot of trouble, such as SharePoint file saving. Then you want to use Django to create an app to record.

Using MySQL + PYTHON + AJAX

1. Configure the database

DATABASES = {     'default': {             'ENGINE':'Django.db.backends.mysql', #使用MYSQL engine'NAME':'Alert', #数据库名字, DatabaseName'USER':'Root','PASSWORD':'1234',             'HOST':"', #为空的话默认: localhost'PORT':'3306', #MYSQL default port 3306}}

2. Create the appropriate app

>python manage.py Startapp Alert

2.1 Here I first set up the existing database, will use INSPECTDB to map the models.py, the output is redirected to model.py

>python manage.py inspectdb > alert/models.py

2.2 If you do not create a db, you can define the model class in models.py (Intercept fragment below) and then use the Python manage.py syncdb to create the corresponding db/table, which is estimated to be the so-called ORM.

..... <skip>..
ClassAlertmaster (models. Model): ID= Models. Integerfield (db_column='ID', primary_key=true)#Field name made lowercase.Production_day = models. Charfield (max_length=45, blank=True) Silo= Models. Charfield (db_column='SILO', max_length=45, Blank=true)#Field name made lowercase.Server = models. Charfield (db_column='Server', max_length=45, Blank=true)#Field name made lowercase.
..... <skip>..

2.3 Don't forget to add the newly created app to the setting.py

Installed_apps = (   'Django.contrib.auth',      'Django.contrib.contenttypes',      'django.contrib.sessions',      'django.contrib.sites',      'django.contrib.messages',      'Django.contrib.staticfiles',      'Django.contrib.admin',     'Django.contrib.admindocs',      ' alert ',)

2.4 Register the table in the admin page

Admin.site.register (models. Alertmaster)

3. The next step is to write views.py, which will be where you spend a lot of time.

Put in the next article

My first Django Project-<django + MySQL + ajax> (1)

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.