Django 1.8安装使用

时间:2022-06-30 23:25:46

1、使用pip安装django, pip是什么,如何安装?自行放狗搜

# pip install "django<1.9"

2、创建项目

# django-admin startproject djangosite

3、运行项目

# cd djangosite

# python manage.py runserver 10.211.55.21:91

运行过程中如果报错
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3

请依次安装,安装下面两个包之后,就可以运行了

# yum install sqlite-devel

# pip install pysqlite

# 启动django程序后,如果提示如下警告

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

很明显,已经告诉我们怎么做了,那就执行一下:python manage.py migrate
话说这个migrate是干什么的呢,它可以让我们在修改Model后可以在不影响现有数据的前提下重建表结构。

(或者在settings.py里加上这么一句:TEST_RUNNER = 'django.test.runner.DiscoverRunner')

现在在运行一次,应该不会有什么问题了

[root@localhost djangosite]# python manage.py runserver 10.211.55.21:9100
Performing system checks...

System check identified no issues (0 silenced).
July 25, 2015 - 04:40:43
Django version 1.8.3, using settings 'djangosite.settings'
Starting development server at http://10.211.55.21:9100/
Quit the server with CONTROL-C.