Skip to content

Commit

Permalink
1st lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
Huangxiaojun committed Jun 5, 2017
1 parent cd2e4c7 commit 0ede7f2
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
95 changes: 95 additions & 0 deletions source/django_tutorials/FirstDay.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
*****************
第一课
*****************

* Django版本:1.11.2
* Pthon版本:3.6.1

安装
=============

::

pip install django

开始
=============
创建项目::

django-admin startproject mysite

项目结构::

G:\MYSITE
│ manage.py
└─mysite
│ __init__.py
│ urls.py
│ wsgi.py
└─ settings.py

开发服务器(在 manage.py 文件目录下运行)::

python manage.py runserver
python manage.py runserver 8080 #8080端口运行
python manage.py runserver 0:8000 #监听所有网卡ip

创建app::

python manage.py startapp polls

app结构::

polls
│ __init__.py
│ admin.py
│ apps.py
│ models.py
│ tests.py
│ urls.py
├─ views.py
└─ migrations
__init__.py

写第一个view
=====================

polls/views.py

.. code-block:: python
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
写url指向这个view

polls/urls.py

.. code-block:: python
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
在root URLconf里调用polls.url模块

mysite/urls.py

.. code-block:: python
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
**注意:** include方法的正则表达式不能以 ``$`` 结尾。
8 changes: 8 additions & 0 deletions source/django_tutorials/chapters.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Django 学习
========================

.. toctree::
:maxdepth: 1
:glob:

./*
1 change: 1 addition & 0 deletions source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ My NoteBook
installation_openssh
cheatsheet
git_guide
django_tutorials/chapters.rst

Indices and tables
==================
Expand Down

0 comments on commit 0ede7f2

Please sign in to comment.