if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djblog.settings") try: from django.core.management import execute_from_command_line except ImportError: # The above import may fail for some other reason. Ensure that the # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: import django except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) raise execute_from_command_line(sys.argv)
开启服务
plaintext
C:\Users\Herrera\djangoopt\djblog>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. March 17, 2018 - 14:22:42 Django version 1.10.6, using settings 'djblog.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. [17/Mar/2018 14:23:25] "GET / HTTP/1.1" 200 1767 [17/Mar/2018 14:25:03] "GET / HTTP/1.1" 200 1767
说明服务已开启 登陆http://127.0.0.1:8000/ 查看:
ceshi
命令栏工具下按 Ctrl + c 可以退出开发服务器(按一次没用的话连续多按几次)。重新开启则再次运行 python manage.py runserver 。
C:\Users\Herrera\djangoopt\djblog>python manage.py makemigrations Migrations for 'blog': blog\migrations\0001_initial.py: - Create model Category - Create model Post - Create model Tag - Add field tags to post
C:\Users\Herrera\djangoopt\djblog>python manage.py migrate Operations to perform: Apply all migrations: admin, auth, blog, 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 blog.0001_initial... OK Applying sessions.0001_initial... OK
C:\Users\Herrera\djangoopt\djblog>python manage.py sqlmigrate blog 0001 BEGIN; -- -- Create model Category -- CREATE TABLE "blog_category" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(100) NOT NULL); -- -- Create model Post -- CREATE TABLE "blog_post" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "title" varchar(70) NOT NULL, "body" text NOT NULL, "created_time" datetime NOT NULL, "modified_time" datetime NOT NULL, "excerpt" varchar(200) NOT NULL, "author_id" integer NOT NULL REFERENCES "auth_user" ("id"), "category_id" integer NOT NULL REFERENCES "blog_category" ("id")); -- -- Create model Tag -- CREATE TABLE "blog_tag" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(100) NOT NULL); -- -- Add field tags to post -- CREATE TABLE "blog_post_tags" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "post_id" integer NOT NULL REFERENCES "blog_post" ("id"), "tag_id" integer NOT NULL REFERENCES "blog_tag" ("id")); CREATE INDEX "blog_post_4f331e2f" ON "blog_post" ("author_id"); CREATE INDEX "blog_post_b583a629" ON "blog_post" ("category_id"); CREATE UNIQUE INDEX "blog_post_tags_post_id_4925ec37_uniq" ON "blog_post_tags" ("post_id", "tag_id"); CREATE INDEX "blog_post_tags_f3aa1999" ON "blog_post_tags" ("post_id"); CREATE INDEX "blog_post_tags_76f094bc" ON "blog_post_tags" ("tag_id"); COMMIT;