Django #1: Project Start up
Initialize a project To initialize a project, run the following command: django-admin startproject name_of_the_project Note that name_of_the project can not be test or django as they will have conflicts. After running the command, it will automatically generate some files. The file structure looks like below: name_of_project |--__init__.py |--asgi.py |--settings.py |--urls.py |--wsgi.py manage.py The function of these files are as below: settings.py: Settings/configuration for this Django project. 配置文件 urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site. asgi.py: An entry-point for ASGI-compatible web servers to serve your project. wsgi.py: An entry-point for WSGI-compatible web servers to serve your project. Creating an APP After initialize Django, we can now start creating an APP. To create an APP, run the following command: python manager.py startapp name_of_your_app It will then create a directory called name_of_your_app with the following files name_of_your_app|--__init__.py|--admin.py|--apps.py|--migrations |--__init__.py|--models.py|--tests.py|--views.py We can define different views within views.py. A view takes a web request and returns a response. This response can be rendered HTML, JSON, XML, etc. After writing a view, we…