码迷,mamicode.com
首页 > 其他好文 > 详细

Django-1.9

时间:2015-12-18 13:25:27      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:django

安装验证:

tar -zxvf tar -zxvf Django-1.9.tar.gz

cd Django-1.9/

python setup.py install

python

>>> import django

>>> print(django.get_version)

>>> print(django.get_version())

1.9


新建项目:

django-admin.py startproject king


vi /opt/king/king/settings.py

# Application definition

INSTALLED_APPS = [

    ‘django.contrib.admin‘,

    ‘django.contrib.auth‘,

    ‘django.contrib.contenttypes‘,

    ‘django.contrib.sessions‘,

    ‘django.contrib.messages‘,

    ‘django.contrib.staticfiles‘,

#wc add1

    ‘king.jobs‘,

]


# Database

# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {

    ‘default‘: {

        ‘ENGINE‘: ‘django.db.backends.sqlite3‘,

        ‘NAME‘: os.path.join(BASE_DIR, ‘db.sqlite3‘),

#wc add2

‘USER‘: root,

‘PASSWORD‘: 123456,

‘HOST‘: localhost,

‘PORT‘: 3306,

    }

}


vi /opt/king/jobs/models.py

# Create your models here.

#wc add1

class Location(models.Model):

    city = models.CharField(maxlength=50)

    state = models.CharField(maxlength=50, null=True, blank=True)

    country = models.CharField(maxlength=50)


    def __str__(self):

        if self.state:

            return "%s, %s, %s" % (self.city, self.state, self.country)

        else:

            return "%s, %s" % (self.city, self.country)


class Job(models.Model):

    pub_date = models.DateField()

    job_title = models.CharField(maxlength=50)

    job_description = models.TextField()

    location = models.ForeignKey(Location)


    def __str__(self):

        return "%s (%s)" % (self.job_title, self.location)


cd ..

python manage.py sql jobs


参考文献:

http://www.ibm.com/developerworks/cn/linux/l-django/

Django-1.9

标签:django

原文地址:http://guowang327.blog.51cto.com/6513732/1725889

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!