Rootop 服务器运维与web架构

django初试

版本 python2.7 需要django 1.11.x版本

https://github.com/django/django

解压
安装
python setup.py install

创建一个项目:
[root@localhost home]# django-admin startproject djtest

启动服务:
[root@localhost djtest]# python manage.py runserver
Performing system checks…

System check identified no issues (0 silenced).
# 报错
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run ‘python manage.py migrate’ to apply them.

解决:
[root@localhost djtest]# python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial… OK
Applying auth.0001_initial… OK
Applying admin.0001_initial… OK
Applying admin.0002_logentry_remove_auto_add… OK
Applying contenttypes.0002_remove_content_type_name… OK
Applying auth.0002_alter_permission_name_max_length… OK
Applying auth.0003_alter_user_email_max_length… OK
Applying auth.0004_alter_user_username_opts… OK
Applying auth.0005_alter_user_last_login_null… OK
Applying auth.0006_require_contenttypes_0002… OK
Applying auth.0007_alter_validators_add_error_messages… OK
Applying auth.0008_alter_user_username_max_length… OK
Applying sessions.0001_initial… OK

[root@localhost djtest]# python manage.py runserver 0.0.0.0:9999
监听所有ip的9999端口

2、访问django报错
Invalid HTTP_HOST header: ‘192.168.1.41:9999’. You may need to add u’192.168.1.41′ to ALLOWED_HOSTS.
修改 settings.pyALLOWED_HOSTS = []ALLOWED_HOSTS = [‘*’]

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/3973.html

作者:Venus

服务器运维与性能优化

评论已关闭。