1. Project structure
Project Address: Https://github.com/timscm/myblog.git
2. Start the project
Start the project with Pycharm and enter debug mode:
"D:\Program files\jetbrains\pycharm 2018.1.3\bin\runnerw.exe"C:\Python365\python.exe"D:\Program files\jetbrains\pycharm 2018.1.3\helpers\pydev\pydevd.py"--multiproc--qt-support=auto--client 127.0.0.1--port 51807--file d:/pycharm/myblog/manage.py runserver 8000Pydev debugger:process11624 isconnectingconnected to Pydev debugger (build181.4892.64) Pydev debugger:process4136 isconnectingperforming System checks ... System Check identified no issues (0 silenced). you haveUnapplied migration (s). Your Project May notWork properly until you apply the migrations forapp (s): admin, Auth, contenttypes, sessions. Run'python manage.py Migrate'To apply them. June03, 2018-22:08:49Django version2.0.5, using Settings'myblog.settings'starting Development Server at http:127.0.0.1:8000/Quit the server with CTRL-break.
View Code
Visit: Http://127.0.0.1:8000/
3. Introduction of documents
Django-admin:django management commands, Django-admin Startproject MyBlog is used to create myblog projects.
manage.py: This file is used to manage operations within the project, Python manage.py startapp polls.
Db.sqlite3: When using Sqlite3, the data file path:
myblog/: The top-level MyBlog directory is just a directory, can be modified to any directory name, but the internal MyBlog directory, it is not easy to modify, it is the Project module package directory name.
__init__.py: Identifies the current myblog/directory as a python module package
settings.py: Project code-level settings file, including: Project Installed app, loaded middleware, first urlconf file path, template related configuration, WSGI application configuration, database configuration, password Authentication configuration, language and time zone configuration, static URL path configuration.
urls.py: When settings's root_urlconf = ' myblog.urls ' Specifies the front-end access HTTP service, the first URL file path is parsed, and the file is stored in a parse relationship between the URL and the Python/django view Code
wsgi.py: When deploying a Django project using Http/nginx, it is introduced into the Python/django code through this file.
templates/: This directory can be considered as the Django parsing static files, the search directory, this directory needs to settings.py in the templates variable dirs Specify the directory's path value to achieve
4. Initialize the configuration
allowed_hosts = [' 192.168.20.100 '] This option is used to configure a collection of IP address lists for external service, fill in the values, have its specific format, will be introduced in depth later.
Language_code = ' Zh-hans ' chinese language code time_zone = ' Asia/shanghai ' project is in the time zone #USE_TZ = True use time zone function off, after this shutdown, does not save In the UTC time zone problem, there is really no need to 5 for projects that serve only a single region. Start Project
6. Create an App
7. Introducing the App
Modify myblog/settings.py, add the app to load
myblog/urls.py:
polls/urls.py
polls/views.py
After starting the service, visit: http://127.0.0.1:8000/polls/
[Timlinux] MyBlog create the first app