django

本文详细介绍了使用Django框架进行Web应用开发的过程,包括模型定义、视图实现、URL配置、模板使用、静态资源管理及部署到Apache服务器的方法。重点强调了数据库操作、表单提交处理、数据分页、错误处理等关键环节,以及如何利用Django的管理后台进行数据迁移和管理。同时,还涉及到静态资源访问、模板继承、模板变量获取和展示等内容。

1,aciton--->url.py---->class method

2,json + key value,value can be dictionary can be array and array can be emmbed dictionary

3,encode set on the first line #coding=utf-8

4,ojweb2

|-media

|-static

|-|-js

|  |-css

|-templates

|-|...(template html files)

|-web

|-|-__init__.py

|  |-models.py

|  |-views.py

|-__init.py__

|-settings.py

|-urls.py

|-wsgi.py

5,notice directory of static,same directory with wsgi

6,参数中如果使用“*”元组参数或者“**”字典参数,这两种参数应该放在参数列表最后。并且“*”元组参数位于“**”字典参数之前。

7,蛋疼了一个小时,# cur.execute("update goods set (goodsDesc,totalPrice,leastPay,monthSold,iconUrl) values(%s,%s,%s,%s,%s) where gId = %s",value)

            cur.execute('update goods set goodsDesc=%s,totalPrice=%s,leastPay=%s,monthSold=%s,iconUrl=%s where gId = %s',value)

8,static,template都必须设置,才能访问图片和 HTML静态资源,好蛋疼的说

9, url(r'^addGoods/$', 'Action.dataManager.index'),

    url(r'^addGoods/aGoods/$','Action.dataManager.addGoods'),$是用来结束的,而^指前面的任意,

10,    print request.GET['goodsDesc'],呵呵键值对,

11, -name mysql.sock这个文件 只有当 MySQL socket启动了之后 才有的

12,form表单提交    return render_to_response('index.html', context_instance=RequestContext(request)),{% csrf_token %}

13,强大的migraine 数据迁移功能,就是 表结构发生变化,自动修改表结构

14,模块都是以APP形式来管理的

15,python manage.py startapp books,创建一个APP,

16,python manage.py syncdb #直接执行SQL语句,只用来检查是否表存在,如果没有,就创建新的表,

17,python manage.py makemigrations

如果model中的数据有改动,这一句执行就没有用。

17,标签:整除divisibleby

18,没有过去到这个值,MultiValueDictKeyError,post方法,而不是 get方法,

19,转JSON    data = serializers.serialize("json", Student.objects.all())

20,直接输入make 完事了输入make install, a,make,b,makeinstall,先 ./configure,然后再make,哈哈

21,brew install libjpeg

22,pip install PIL --allow-external PIL --allow-unverified PIL

23,

8

down vote

Try to go to Window -> Preferences -> Pydev-> Interpreter -> Python Interpreter -> Forced Builtins tab. Then add a PIL entry and apply. I've had the same unresolved import error when tried to import from this particular package (other packages worked fine), and found this information which finally helped me.

24,静态数据的响应 用的都是 static,内置的APP,内置的服务,

25,

static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

MEDIA_URL = '/template/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'CurdJango/template')

http://127.0.0.1:8000/template/photos/b.png

拦截template请求,然后去CurdJango/template 目录里面 寻找 /photos/b.png

26,enctype="multipart/form-data",这个是必须的,

27,Error cannot concatenate 'str' and 'type' objects

28,分页功能,查找功能,总是要有,数据多了就要分开显示,数据多了就要查找,这个是必须的,

29,Error when calling the metaclass bases

    unbound method contribute_to_class() must be called with FloatField instance as first argument (got ModelBase instance instead)

 leastPrice = models.FloatField()

    monthSold = models.IntegerField()记住加括号

30    imageurl = models.FileField(upload_to = './photos/')

类型

 

31, <input name="goodsDesc" type="text" value="{{ data.goodsDesc  }}">

        <br/> 商品价格:

         <input name="name" type="text" value="{{ data.totalPrice  }}">注意前后name对应

 

 

Django部署到Apache

1,wsgi

import sys

sys.path.append(‘/Library/WebServer/Documents/gallery-master/')

2,httpd

LoadModule wsgi_module /usr/libexec/apache2/mod_wsgi.so

 

WSGIScriptAlias /gallery /Library/WebServer/Documents/gallery-master/gallery/wsgi.py  

WSGIPythonPath /Library/WebServer/Documents  

gallery 这个名字对应 项目访问的名字

 

<Directory "/Library/WebServer/Documents/gallery-master/">  

<Files wsgi.py>  

Order deny,allow  

Allow from all  

</Files>  

</Directory>  

 

Alias /templates/ /Library/WebServer/Documents/gallery-master/items/templates  

<Directory /Library/WebServer/Documents/gallery-master/items/templates>  

Allow from all  

</Directory>  

 

 

alias /static /Library/WebServer/Documents/gallery-master/static/

<Directory "/Library/WebServer/Documents/gallery-master/static/">

    Order deny,allow

    Allow from all

</Directory>

 

setting.py ALLOWED_HOSTS = ['localhost']  

 

MEDIA_URL = '/CurdJango/CurdJango/template/'

这个比玩意是根请求相关的,)+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

 

 

<td><img src="/CurdJango/template/{{d.iconUrl}}" </img> </td>

这个路径修改下,就可以显示了,前端HTMl添加上 项目名字

 

 

转载于:https://www.cnblogs.com/guligei/p/4332450.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值