team470 发表于 2015-4-23 07:32:10

Python 网站建设

  一、CentOS5.0下环境搭建
  python2.5安装, gae(https://developers.google.com/appengine) 支持2.5 2.7版本,而CentOS5下默认为2.4版本,不过因yum需要python2.4,所以不能删除原来版本。
  wget http://www.python.org/ftp/python/2.5/python-2.5.tar.bz2
  tar jxvf python-2.5.tar.bz2
  cd python-2.5
  ./configure --prefix=/usr/local   #安装在指定目录,避免覆盖旧版本,不过默认安装好像也不会(blog.iyunv.com/csapr1987/article/details/7659397)
  make
  make install
  测试发现,python 自动调用2.5版本,而且yum正常,gae使用正常,perfect
  
二、pathon入门
  python 简明教程 http://woodpecker.org.cn/abyteofpython_cn/chinese/
  笨办法学python http://learn-python-the-hard-way-zh_cn-translation.readthedocs.org/en/1.0/index.html
  摘要:
  两种方法运行程序 1. python ext1.py
  2. chmod a+x ext1.py
  #!/usr/bin/python或者 #!/usr/local/bin/python
  ./ext1.py
  单引号和双引号一样,%r万能格式化输出,import 导入模组(modules)
  表达式,函数需要冒号
  if 表达式: else:
  函数 def print_demo(arg1,arg2):
  print arg1,arg2
  return none
  python 源代码网站   bitbucket.orggithub.comlaunchpad.netkoders.com
  
  三、 Django学习
  官网:www.djangoproject.com
  The Django book http://djangobook.py3k.cn
  安装:
  tar.xzvf.Django-1.4.tar.gz
  cd Django-1.4
  python setup.py install
  验证:
  >>>import django
  >>>python django.get_versin()
  创建:
  django-admin.py startproject mysite
  python manage.py runserver 8080
  文件目录:
  mysite
  mysite
  __init__.py      让python将该目录当成开发包,即一组模块
  settings.py      数据库等设置
  urls.py            路由
  wsgi.py
  manage.py            命令行工具
  
四、安装mysql数据库支持,mysql-python是python操作mysql数据库的组建,其moudle name为 MySQLdb
  测试:
  >>>import MySQLdb
  error: No module named mysqldb 说明未安装
  下载:
  Mysql-python-1.2.3.tar.gz       (sourceforge.net/projects/mysql-python) 
  tar.xzvf Mysqll-python-1.2.3.tar.gz
  cd Mysql-python-1.2.3
  python setup.py bulid
  python setup.py install
  
  出现 Import ErrorNo module name setuptools 说明需要安装setuptools    (cetos 5.0)
  wget http://pypi.python.org/packages/soucers/setuptools/setuptools-0.6c11.tar.gz
  tar zxcf setuptools-0.6c11.tar.gz
  cd setuptools-0.6c11
  python setup.py bulid
  python setup.py install
  
五、网站部署(gae)
  支持python的免费站点 dot cloud, heroku, gae, sae, baidu
  goagentFQ代理,gae的应用需要FQ http://maolihui.com/goagent-detailed-version-of-the-tutorial.html
  1>goagent 代理基于gae, 已经开通gae项目的ID不能再goagent使用
  2>chrome安装swithysharp Firfox安装Foxyproxyhttps://code.google.com/p/goagent/
  参考:https://developers.google.com/appengine/docs/python/gettingstarted/uploading
  myapp
  app.yaml         配置文件
  helloword.py    网站脚本
  yaml内容:
  application: yourprojectid
  version: 1
  runtime: python
  api_version: 1
  handlers:
  - url: /stylesheets
  static_dir: stylesheets
  - url: /.*
  script: helloworld.py
  上传代码:
  appcfg.py update helloworld/
  访问:yourprojectid.appspot.com (需墙)

 

  
  
  
  
  
  
  
  
  
  
  
页: [1]
查看完整版本: Python 网站建设