python manage.py startapp cmdb
python manage.py startapp openstack
migrations 记录数据文件
admin django提供的后台管理
apps 配置的
models orm建表的
tests 单元测试的
views app 业务的代码
--------------------内容整理-----------------
djang-admin-exe startproject mysite
cd mysite
python manage.py runserver 127.0.0.1:8001
-------
django-admin startproject project-name
cd project-name
python manage.py startapp cmdb
-----------------------------------
模板配置
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
静态文件:static->append
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
-----------setting中 注释csrf------------
定义视图函数
app 下views.py
def function(request):
#request.method GET/POST
http://127.0.0.1:8009/home?nid=123&name=alex
request.GET.get('',None)
return httpResponse("字符串")
return render(request,"模板的路径")
return redirect(‘/只能是url’)
模板渲染:
return render(request,"index.html",{'current_user'}:"alex",'user_list':['alex','errif'],
'user_list':{'k1':'v1','k2':'v2'})
index.html
<html>
<body>
<div>{{current_user}}</div>
<ul>
{% for row in user_list %}
<li>{{row}}</li>
{%endfor%}
</body>
</html>