Django---the python script mysql

Source: Internet
Author: User
Tags documentation sessions python script

#######

Installing PYTHON-MYSQLDB

##############

[Email protected] myweb]# pwd

/tmp/python/django-1.5.1/django/bin/myweb/myweb

[Email protected] myweb]# VI settings.py

DATABASES = {

' Default ': {

' ENGINE ': ' Django.db.backends. MySQL', # Add ' postgresql_psycopg2 ', ' MySQL ', ' sqlite3 ' or ' Oracle '.

' NAME ': 'python', # Or path to database file if using Sqlite3.

# The following settings is not used with Sqlite3:

' USER ': 'root',

' PASSWORD ': '123456',

' HOST ': ', # Empty for localhost through domain sockets or ' 127.0.0.1 ' for localhost through TC

P.

' PORT ': ', # Set to empty string for default.

}

}

Installed_apps = (

' Django.contrib.auth ',

' Django.contrib.contenttypes ',

' Django.contrib.sessions ',

' Django.contrib.sites ',

' Django.contrib.messages ',

' Django.contrib.staticfiles ',

# Uncomment the next line to enable the admin:

# ' Django.contrib.admin ',

# Uncomment the next line to enable admin documentation:

# ' Django.contrib.admindocs ',

'pyweb'

[Email protected] myweb]# pwd

/tmp/python/django-1.5.1/django/bin/myweb

[Email protected] myweb]#/manage.py Startapp pyweb

[Email protected] pyweb]# pwd

/tmp/python/django-1.5.1/django/bin/myweb/pyweb

[Email protected] pyweb]# VI models.py

From django.db import Models


# Create your models here.

From django.db import Models


Class Publisher (models. Model):

Name = models. Charfield (max_length=30)

Address = models. Charfield (MAX_LENGTH=50)

City = models. Charfield (max_length=60)

State_province = models. Charfield (max_length=30)

Country = models. Charfield (MAX_LENGTH=50)

Website = models. Urlfield ()

def __unicode__ (self):

Return Self.name

Class Author (models. Model):

First_Name = models. Charfield (max_length=30)

Last_Name = models. Charfield (MAX_LENGTH=40)

email = models. Emailfield ()

def __unicode__ (self):

Return Self.name


Class book (Models. Model):

title = models. Charfield (max_length=100)

Authors = models. Manytomanyfield (Author)

Publisher = models. ForeignKey (Publisher)

Publication_date = models. Datefield ()

def __unicode__ (self):

Return Self.name

[Email protected] myweb]# pwd

/tmp/python/django-1.5.1/django/bin/myweb

[email protected] myweb]# python manage.py validate

0 errors found

[email protected] myweb]# python manage.py sqlall pyweb

[email protected] myweb]# python manage.py syncdb

[[email protected] myweb]#./manage.py Shell

In [3]: P1 = Publisher (name= ' Shanghai ', address= ' 24242 Chuansha Road ', city= ' Shanghai ', state_province= ' CN ', country= ' China ', website= ' http://www.xxk.com/')

In [4]: P1.save ()


In [5]: p1.name= ' Hefei '

In [6]: P1.save ()

---------------------------------------------------Web site

[Email protected] myweb]# pwd

/tmp/python/django-1.5.1/django/bin/myweb/myweb

[Email protected] myweb]# VI settings.py

Installed_apps = (

' Django.contrib.auth ',

' Django.contrib.contenttypes ',

' Django.contrib.sessions ',

' Django.contrib.sites ',

' Django.contrib.messages ',

' Django.contrib.staticfiles ',

# Uncomment the next line to enable the admin:

' Django.contrib.admin ',

# Uncomment the next line to enable admin documentation:

# ' Django.contrib.admindocs ',

' Pyweb '

)

[Email protected] myweb]# VI urls.py

From Django.conf.urls import patterns, include, url


# Uncomment the next lines to enable the admin:

From Django.contrib Import admin

Admin.autodiscover ()

From Myweb.view import Hello,current_time,cpu,hours_ahead

From MYWEB.VIEW2 import disk


Urlpatterns = Patterns ("',

# Examples:

# URL (R ' ^$ ', ' myweb.views.home ', name= ' home '),

# URL (R ' ^myweb/', include (' Myweb.foo.urls ')),


# Uncomment the Admin/doc line below to enable admin documentation:

# URL (R ' ^admin/doc/', include (' Django.contrib.admindocs.urls ')),


# Uncomment the next line to enable the admin:

URL (r ' ^admin/', include (Admin.site.urls)),

(R ' ^hello/$ ', hello),

(R ' ^time/$ ', current_time),

(R ' ^cpu/$ ', CPU),

(R ' ^time/plus/(\d{1,2})/$ ', Hours_ahead),

(R ' ^disk/$ ', disk),

)

[Email protected] pyweb]# VI admin.py

From Django.contrib Import admin

From pyweb.models import Publisher, Author, book

Admin.site.register (Publisher)

Admin.site.register (Author)

Admin.site.register (book)

[Email protected] myweb]#/manage.py syncdb


Http://192.168.1.10:8000/admin/created when #用户名和密码为第一次执行python manage.py syncdb










Django---the python script mysql

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.