安装成功:
Installed /usr/local/lib/python2.7/dist-packages/pytz-2019.1-py2.7.egg
Finished processing dependencies for Django==1.11.20
创建项目:
ubuntu@ubuntu:~/Django-1.11.20$ django-admin startproject HelloWorld
ubuntu@ubuntu:~/Django-1.11.20$ cd HelloWorld/
ubuntu@ubuntu:~/Django-1.11.20/HelloWorld$ django-admin
Type 'django-admin help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runserver
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
ubuntu@ubuntu:~/Django-1.11.20/HelloWorld$ ls
HelloWorld manage.py
进入 HelloWorld 目录输入以下命令,启动服务器
ubuntu@ubuntu:~/Django-1.11.20/HelloWorld$ python manage.py runserver 256.256.256.256:8000(私人对外ip)
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.
April 18, 2019 - 18:28:53
Django version 1.11.20, using settings 'HelloWorld.settings'
Starting development server at http://256.256.256.256:8000/
Quit the server with CONTROL-C.
^Cubuntu@ubuntu:~/Django-1.11.20/HelloWorld$ 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
ubuntu@ubuntu:~/Django-1.11.20/HelloWorld$ python manage.py runserver 256.256.256.256:8000
Performing system checks...
System check identified no issues (0 silenced).
April 19, 2019 - 05:32:06
Django version 1.11.20, using settings 'HelloWorld.settings'
Starting development server at http://256.256.256.256:8000/
Quit the server with CONTROL-C.
Invalid HTTP_HOST header: '256.256.256.256:8000'. You may need to add u'256.256.256.256' to ALLOWED_HOSTS.
[19/Apr/2019 05:32:39] "GET / HTTP/1.1" 400 66524
Invalid HTTP_HOST header: '256.256.256.256:8000'. You may need to add u'256.256.256.256' to ALLOWED_HOSTS.
[19/Apr/2019 05:32:39] "GET /favicon.ico HTTP/1.1" 400 66574
在创建的项目里修改setting.py文件
ALLOWED_HOSTS = ['*'] #在这里请求的host添加了*
保存修改,再次重启服务器:
Performing system checks...
System check identified no issues (0 silenced).
April 19, 2019 - 05:56:38
Django version 1.11.20, using settings 'HelloWorld.settings'
Starting development server at http://256.256.256.256:8000/
Quit the server with CONTROL-C.
[19/Apr/2019 05:56:44] "GET / HTTP/1.1" 200 14
Not Found: /favicon.ico
[19/Apr/2019 05:56:44] "GET /favicon.ico HTTP/1.1" 404 1966