易截截图软件、单文件、免安装、纯绿色、仅160KB

python下的web开发框架 Django,url配置

url配置
我们在polls这个app下创建一个
helloworld.py
from django.http import HttpResponse
def index(request):
    return HttpResponse("Hello, Django.")
修改 urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^newtest/', include('newtest.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^$', 'newtest.helloworld.index'),
# Uncomment the next line to enable the admin:
# (r'^admin/(.*)', admin.site.root),
)
其中
(r'^$', 'polls.helloworld.index'),
r’^$’ 是为了匹配空串 ,就是http://localhost:8000/
r’^$’, ‘polls.helloworld.index’),就是说 http://localhost:8000/ 这个地址将会指向
polls 这个工程里 helloworld.py 文件里定义的index方法,看看helloworld.py里面是不是有个def index(request):
举个例子,如果以后要想让http://localhost:8000/ blog 能被访问,只需要加个
r’^blog’ ,然后在后面写views来控制结果(这个以后会讲),够方便吧!
如果此时 web server已经启动,直接刷新页面就可以看到 hello world 了
很方便,django的url配置helloworld就是这样


相关文档:

Python简易股票查询(抓取google财经的内容)


看着网上抓取网页数据的文章直瞪眼
后来想到用字符串分割来提取相应部分的内容
程序简单,但数行数和下标费了很长时间
我知道这肯定不是最好的办法- -!!
但我实现了,哈哈
# -*- coding: cp936 -*-
from urllib import *
import re
def stockSearch():
    baseurl="http://www.google.cn/financ ......

python 中带星号和双星好的参数


当要使函数接收元组或字典形式的参数的时候,有一种特殊的方法,它分别使用*和**前缀。这种方法在函数需要获取可变数量的参数的时候特别有用。
>>> def powersum(power, *args):
...      '''Return the sum of each argument raised to specified power.'''
...    ......

Python里隐藏的“禅”

在 python的lib目录里有一个:this.py,它其实是隐藏着一首诗,源码如下:
s =
"""Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf ......

BeautifulSoup Python抓网页小例子

# -*- coding: utf-8 -*-
import urllib2
from BeautifulSoup import BeautifulSoup, Tag
import re
page = urllib2.urlopen("http://bj.ganji.com/piao/zz_%E5%8C%97%E4%BA%AC-%E5%8D%97%E6%98%8C/20100210/")
soup = BeautifulSoup(page)
#ss = soup.findAll('a', href=re.compile(r"^/piao/100.&qu ......

Python 练习2

生成一个有N个元素的有随机整数n组成的列表,其中N和年的取值范围是(1<N<=5)
和(0<=n<100),显示这个列表的所有子集。
N个数字空有2en个子集,对于这N个数字在每个子集中来讲要么存在要么不存在,可以采用子集映射为2进制的算法。
例如[a,b]集合的子集:
空      ---- &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号