sudo apt-get installl tree

开始创建工作目录

django-admin.py startproject mysite

创建一个名为 mysite的子目录,然后我们通过tree 命令查看一下目录结构

xpower@xpower-CW65S:~$ tree mysite/
mysite/
├── manage.py
└── mysite
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py directory, files


mysite : 外面的mysite是项目文件的目录名称罢了,Django不在意他的名字,可以将其改为你喜欢的名字。


manage.py :命令行工具集,供我们操作本Django项目,

python3 manage.py help #查看起提供的功能。

注意,千万不要修改该文件。下面我们看一下该文件的内容。

#!/usr/bin/env python
import os
import sys if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.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)

可以看出其是本项目入口文件。


mysite/mysite/ : 这个mysite是我们项目的一个包。


__init__.py : 让python吧mysite目录作文一个包的必须文件。一般情况下文件为空。


setting.py : 该项目的配置文件,通过该文件,我们可以了解到可以了解到可以进行那些配置和已有的默认值。

"""
Django settings for mysite project. Generated by 'django-admin startproject' using Django 1.10.4. For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
""" import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&ey(33(c&&oq)+s%o%*i-xxt=+me2w&c-ka50%s)urmxxahb!h' # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
] MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ROOT_URLCONF = 'mysite.urls' TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] WSGI_APPLICATION = 'mysite.wsgi.application' # Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
} # Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
] # Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/ STATIC_URL = '/static/'

项目中需要的配置信息都在里面,包括运行结构,和网站部署等等。

urls.py : Django的URL设置,网站目录。

wsgi.py : 是兼容WSGI的Web服务器伺服你的项目的入口文件。更多细节请查阅“如何通过WSGI部署”(https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/)。



下面我们看一下 manage.py可以提供的服务。

xpower@xpower-CW65S:~/mysite$ python3 manage.py help

Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[auth]
changepassword
createsuperuser [django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver [sessions]
clearsessions [staticfiles]
collectstatic
findstatic
runserver

通过以上信息,我们开始运行我们的开发服务器。

python3 manage.py runserver

得到如下信息表示成功启动

xpower@xpower-CW65S:~/mysite$ python3 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. February 13, 2017 - 19:08:59
Django version 1.10.4, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

打开链接可以看到 It‘s worked !界面。

Django自带的这个开发服务器虽然方便,但是它只能在同一时间可靠地处理一个链接,而且没有任何安全检查,在发布我们的站点之前,我们还需要了解如何部署Django。


默认情况下runserver的时候我们启动的是8000端口,上述反馈信息中得出。如果端口占用或者我们需要指定端口的时候使用

python manage.py runserver 8080

弹射起步~django的更多相关文章

  1. 49.Django起步学习

    django起步 django安装 pip install django==2.0.4(版本号) pip install django 默认安装最新版本 创建项目 django-admin start ...

  2. Python3 并发编程4

    目录 Event事件 线程池与进程池 基本概念 使用方法 和信号量的区别 协程(coroutine) 基本概念 实现方式 多线程爬取梨视频 Event事件 用来控制线程的执行 e.isSet()查看对 ...

  3. YARP实现Dapr服务调用的反向代理

    楔子 公司即将新开项目,打算用点时髦的技术,需要探探路.之前没做过微服务项目,没有技术栈方面的积(负)累(债), 干脆就上微软的分布式运行时Dapr......嗯......用来服务发现,然后等测试用 ...

  4. 硬件篇-03-SLAM移动底盘电气设计

      最近因为在忙毕设,专栏已经1个多月没更,对于托更我很抱歉.不过这几周真的没什么时间,Rick&Morty的最新集我到现在都还没看哈哈.     现在毕设已经搞得差不多了,水专栏文章的快乐生 ...

  5. 1.1 Django起步

    1.1 Django起步   1.1.1. Django简介   Django开发框架(简称Django)诞生的时间是2003年的金秋时节,美国有两位程序员Adrian  Holovaty和Simon ...

  6. 小白神器 - Django - 起步

    小白神器 - Django - 起步 一.  Django下载 1. 命令行 pip install django==1.11.16 pip install django==1.11.16 -i ht ...

  7. django celery的分布式异步之路(一) 起步

    如果你看完本文还有兴趣的话,可以看看进阶篇:http://www.cnblogs.com/kangoroo/p/7300433.html 设想你遇到如下场景: 1)高并发 2)请求的执行相当消耗机器资 ...

  8. Django框架起步

    一.环境安装 二.创建项目 三.项目目录 四.创建项目应用 五.应用目录 六.第一个响应 七.第一个模板页面 八.第一个重定向 九.url应用移植 十.多应用相同模板页面冲突 十一.静态资源的配置 十 ...

  9. Django之权限(起步)

    一. 权限概述 1. 认识权限 为什么要有权限? 因为权限让不同的用户拥有不同的功能. 权限可以对功能进行划分. 生活中处处有权限. 比如, 腾讯视频会员才有观看某个最新电影的权限, 你有房间钥匙就有 ...

随机推荐

  1. find the longest of the shortest (hdu 1595 SPFA+枚举)

    find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  2. Codeforces 3A-Shortest path of the king(BFS打印路径)

    A. Shortest path of the king time limit per test 1 second memory limit per test 64 megabytes input s ...

  3. Redis 脚本及其应用

    参考:http://www.runoob.com/redis/redis-scripting.html Redis 脚本使用 Lua 解释器来执行脚本. Reids 2.6 版本通过内嵌支持 Lua ...

  4. error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

    头文件函数声明少了“:(分号)”

  5. vue class与style绑定、条件渲染、列表渲染

    列表渲染 根据我例子的需要,先来说下,列表渲染使用到的是v-for指令,需要使用 item in items 形式的特殊语法,items 是源数据数组并且 item 是数组元素迭代的别名,具体使用方法 ...

  6. angularjs学习之八(angularjs中isolate scope的使用)

    angular js中指令directive有个特别实用的东西,那就是 isolate scope (被隔离的scope) 关于详细他和全局的scope 有什么差别.能够參考以下这篇博文: Angul ...

  7. hadoop shuffle

    1 hadoop shuffle的地位 hadoop  shuffle是map reduce算法的核心,是它连接了多个map和多个reduce,它将map的输出交给reduce作为输入. 2 hado ...

  8. Oracle数据库案例整理-Oracle系统执行时故障-断电导致数据文件状态变为RECOVER

    1.1      现象描写叙述异常断电.数据库数据文件的状态由ONLINE变为RECOVER. 系统显演示样例如以下信息:SQL>selectfile_name,tablespace_name, ...

  9. Ruby中任务构建工具rake的入门

    不同的rake文件当中不要定义重名的方法,不然没法调用 参考:http://www.jb51.net/article/81476.htm Rake简介 Rake的意思是Ruby Make,一个用rub ...

  10. RK3399参考设计方案之DC-DC电源芯片RK808D【转】

    本文转载自:http://www.52rd.com/Blog/Detail_RD.Blog_sunnyqi_90673.html?WebShieldDRSessionVerify=Xv0bsGtD73 ...