Jython 2.2, the first major overhaul of the Jython dynamic scripting language in 4 years, has been released. Jython 2.2 implements the internal architecture of Python 2.2 and includes numerous features from Python 2.3.
The new release includes many major changes:
* new-style classes
* Java Collections integration
* PEP 302 implementation
* iterators
* generators
* __future__ division
* support for running on JDK1.5 and 1.6
* new installer
* a significant number of features to bring Jython in line with CPython
The Jython download is at:
http://sourceforge.net/project/showfiles.php?group_id=12867
The Jython community meets at: http://www.jython.org
http://www.djangoproject.com/documentation/tutorial01/
http://www.djangoproject.com/documentation/tutorial02/
http://www.djangoproject.com/documentation/tutorial03/
http://www.djangoproject.com/documentation/tutorial04/
import urllib2,cookielib
cookie=cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
urllib2.install_opener(opener)
user=raw_input('帐号:')
mm=raw_input('密码:')
login_response= urllib2.urlopen('url' ,postdata)
# -*- coding: utf-8 -*-
# Create your views here.
from django.core.paginator import ObjectPaginator, InvalidPage
from django.template.loader import get_template
from django.http import HttpResponse
from django.template import Template, Context
from datetime import datetime
from attendance.register.models import zqidmsg
def index(request):
t = get_template('index.html')
html = t.render(Context({}))
return HttpResponse(html)
def list_view(reqest):
t = get_template('index_2.html')
q1 = zqidmsg.objects.filter(server='XXX')
pager = ObjectPaginator(q1,3)
try:
pager = ObjectPaginator(q1,3)
# page = int(request.GET.get('page', '1'))
# tags = pager.get_page(page - 1)
except InvalidPage:
raise http.Http404
l_list = pager.get_page(0)
pages= pager.pages
current_page = 1
kk = range(pager.pages+1)[1:]
html =t.render(Context({'kl':l_list,'pager':pager,'kk':kk,'pages':pages,'current_page':current_page}))
#html =t.render(Context({'msg':l_list}))
#data = {'kl':l_list,'pager':pager}
# html =t.render(Context({'kl':l_list}))
return HttpResponse(html)
def attendance(request):
t = get_template('index.html')
now=datetime.now()
p = zqidmsg(di='2',remark='2',server='XXXX',typedesc='XXX',qtitle='XXX',over=0,lat=0,date=now)
p.save()
html = t.render(Context({}))
return HttpResponse(html)
翻译:http://hideto.javaeye.com/category/7645
原文:http://www.djangobook.com/en/beta/
www.cnblogs.com/zhengyun_ustc/archive/2006/11/20/django_apache_win32.html
配置mod_python
1.使用apache_2.0.54-win32-x86-no_ssl.msihttp://archive.apache.org/dist/httpd/binaries/win32/
2.安装mod_python-3.2.8.win32-py2.4.exe
http://apache.justdn.org/httpd/modpython/
mod_python中文文档
http://man.chinaunix.net/develop/python/mod_python/mod_python.h
3.配置Apache2\conf\httpd.conf
添加
LoadModule python_module modules/mod_python.so
<Directory "D:/Apache Group/Apache2/htdocs">
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>
4.浏览http://localhost:8080/mptest.py,测试mod_python是否配置成功
配置Django
http://thinkhole.org/wp/2006/04/03/django-on-windows-howto/Django Step by Step
1.http://tortoisesvn.sourceforge.net/ 下载tortoisesvn
签出http://code.djangoproject.com/svn/django/trunk/django
Copy django 到 E:\Python24\Lib\site-packages\
Copy E:\Python24\Lib\site-packages\django\bin\django-admin.py 到 E:\Python24\Scripts
2.通过shell,运行import django,如果成功运行,证明安装成功
3.创建Web项目,路径E:\mysite
先添加环境变量,Path=E:\Python24\;E:\Python24\Scripts;
建议添加PATHEXT=.py
django-admin.py 就可以不带扩展名执行
E:\mysite>django-admin.py startproject mysite
生成了一个mysite目录,包含__init__.py, manage.py, settings.py, urls.py
__init__.py 说明mysite是一个python包
manage.py 管理应用程序
settings.py 配置应用程序
urls.py URL映射
E:\mysite>python manage.py runserver
查看http://localhost:8000/页面
4.配置到Apache
<Location "/mysite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonPath "['E:\mysite'] + sys.path"
PythonDebug On
</Location>
<Location "/media/">
SetHandler None
</Location>
<LocationMatch "\.(jpg|gif|png)___FCKpd___1quot;>
SetHandler None
</LocationMatch>
浏览http://localhost:8080/mysite/
5.安装数据库
postgresql
http://wwwmaster.postgresql.org/download/mirrors-ftp?file=binary%2Fv8.1.3%2Fwin32%2Fpostgresql-8.1.3-1.zip
SQLite
http://www.sqlite.org/download.html
http://www.initd.org/tracker/pysqlite
从http://pydev.sourceforge.net/download.html上下载到pydev,解压.
将解压后features目录下的一个文件夹拷到c:\eclipse目录下的features目录下,将plugins目录下的三个文件夹手到c:\eclipse目录下的plugins目录下,运行c:\eclipse的eclipse.exe.
进 入eclipse后,选择'help'(帮助)>>'software updates'(软件更新)>>'manage configuration...'(管理配置),打开后点"file"下面的第三个图标,使它和前面两个图标一样成凹下状,这时在左下面可以看见多出了 一个分支,叫"org.python.pydev.feature ",选中它,点右边窗口Available Tasks下面的"Enable",这时就会让你重启eclipse,重启之后就可以了.
也可以通过选择'help'(帮助)> >'software updates'(软件更新)>>Find and Insatll>>Search for new Feature to Install下一中添加一个New Remote Site为http://pydev.sf.net/updates/ ,然后就可以点击下一步自动升级了,这个是直接从网站上下载安装的
Installing with the update site
To install Pydev and Pydev Extensions from the Eclipse Update Manager, you need to go to the install menu:

Then select 'Search for new features for install' (You will follow the same path even if you already have an older version installed).

In the next screen (below), click 'new remote site'

Set the 'Pydev Extensions' update site: http://www.fabioz.com/pydev/updates
NOTE: if you currently have the sourceforge update site, you're advised to remove it (some reports pointed to some problems when having both).
NOTE: The only difference between the sourceforge update site and this one is that the one at sourceforge only contains the Pydev 'Open Source' version, and this one contains both.

Click 'Finish'. You should be presented with the screen below:

Select both features and click 'next'...
NOTE: if the features do not appear to you, you should restart Eclipse and try again (that's because Eclipse caches the results, and sometimes it may have the wrong version in its cache -- which is only cleared when you restart Eclipse).

Now, you'll have to accept the license, click 'next' and in the next screen, review it and click 'finish'. Eclipse should automatically download the plugin contents and present you to a dialog asking if you want to restart (to which you should say yes).
Installing with the zip file
After downloading the zip file (from http://www.fabioz.com/pydev/zips), you have to extract it yourself on top of Eclipse. If you choose to do it, just make sure the plugins folder is extracted on top of the Eclipse plugins folder. After that, restart it with the '-clean' flag, to make sure Eclipse finds out about it.
Checking the installation
You can verify if it is correctly installed going to the menu 'help > about > plug in details' and checking if there are at least 5 plugins with the 'plug-in Id' starting with 'com.python.pydev' and at least other 5 starting with 'org.python.pydev' (and check if they have the version you got).
Uninstalling
If at any time you wish to stop using the Pydev extensions plugin (or any other Eclipse plugin), you can disable it by going to the menu 'help > software updates > manage configuration', selecting the plugin and clicking 'disable', then, you have to restart Eclipse, go to the same place again and then click on 'remove' (note that you have a button in the menu that enables you to see the 'disabled' features.
Most commom problems
Corrupted install: Eclipse sometimes is not able to correctly get the plugin, but will do no checking on whether it is really correct (no md5 checking), and when this happens, you'll usually get a ClassNotFoundException (similar to the example below).
When that happens, you should uninstall it and reinstall again with the update site... if that still fails, you could try to get the zip files, as it will at least give you a warning when it is corrupt.
-- the chance of the files being corrupt in the server is pretty low, as that's something that's always checked in a new release -- but if you're suspicious about it, please contact me, so that I can double-check it.
Also, there have been reports with that error where the only solution that has been consistent has been removing all previous versions of pydev and then installing the latest version.
EXAMPLE
Unable to create this part due to an internal error. Reason for the failure: The editor class could not be instantiated. This usually indicates that the editor's class name was mistyped in plugin.xml.
java.lang.ClassNotFoundException: org.python.pydev.editor.PyEdit
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:405)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:350)
at org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass(AbstractClassLoader.java:78)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:275)
...
代码如下:
#!/usr/local/bin/python
#FileName = test_Web.py
#get from db
#http://192.168.1.74/spaces/posts/postdetail.aspx?id=
#put into db
#http://192.168.1.74/admin/space/post/post_add.aspx?fid=0&um=300372&v=__VERSION__&title=0&content=hahaasdfasdf
import thread, time, urllib
id_index = 100000
id_count = 20000
id_max = id_index+id_count
i_cnt = 0
time_begin = time.time()
bStop = False
def openurl():
sock = urllib.urlopen("http://192.168.1.74/admin/space/post/post_add.aspx?fid=0&um=300372&v=__VERSION__&title=0&content=hahaasdfasdf")
htmlSource = sock.read()
#print htmlSource
sock.close()
def opengeturl(id):
strUrl = "http://192.168.1.74/spaces/posts/postdetail.aspx?id=%d" % id
print strUrl
sock = urllib.urlopen(strUrl)
htmlSource = sock.read()
#print htmlSource
sock.close()
def child( myID ): # this function runs in threads
while( True ):
global id_index
global id_max
global id_count
global time_begin
global bStop
global i_cnt
if( i_cnt > id_count ):
now = time.time()
i_handle_time = now - time_begin
if( bStop == False ):
print "%d rows cost %f second" % ( id_count, i_handle_time )
bStop = True
break
#id_index = id_index + 1
i_cnt = i_cnt + 1
print "[%d] ==> %d" % (myID, id_index)
opengeturl(id_index)
time.sleep(1)
for i in range( 500 ): # spawn 3 threads
thread.start_new( child, (i,) )
time.sleep(1000000)
print 'Main thread exiting.' # don't exit too early
1. 各种实用代码片段
1.1. 正则表达式使用
###########################################################
特殊字符:
###########################################################
"." 匹配除 "\n" 之外的任何单个字符。要匹配包括 '\n' 在内的任何字符,请使用象 '[.\n]' 的模式。
"^" 匹配输入字符串的开始位置。
"___FCKpd___0quot; 匹配输入字符串的结束位置。
"*" 匹配前面的子表达式零次或多次。例如,zo* 能匹配 "z" 以及"zoo"。 * 等价于{0,}。 Greedy means 贪婪的
"+" 匹配前面的子表达式一次或多次。例如,'zo+' 能匹配 "zo" 以及 "zoo",但不能匹配 "z"。+ 等价于 {1,}。
"?" 匹配前面的子表达式零次或一次(贪婪的)
*?,+?,?? 前面三个特殊字符的非贪婪版本
{m,n} 最少匹配 m 次且最多匹配 n 次(m 和 n 均为非负整数,其中m <= n。)
{m,n}? 上面表达式的非贪婪版本.
"\\" Either escapes special characters or signals a special sequence.
[] 表示一个字符集合,匹配所包含的任意一个字符
第一个字符是 "^" 代表这是一个补集
"|" A|B, 匹配 A 或 B中的任一个
(...) Matches the RE inside the parentheses(圆括号).(匹配pattern 并获取这一匹配)
The contents can be retrieved(找回) or matched later in the string.
(?iLmsux) 设置 I, L, M, S, U, or X 标记 (见下面).
(?:...) 圆括号的非成组版本.
(?P<name>...) 被组(group)匹配的子串,可以通过名字访问
(?P=name) 匹配被组名先前匹配的文本(Matches the text matched earlier by the
group named name.)
(?#...) 注释;被忽略.
(?=...) Matches if ... matches next, but doesn't consume the
string(但是并不消灭这个字串.)
(?!...) Matches if ... doesn't match next.
The special sequences consist of "\\" and a character from the list
below. If the ordinary character is not on the list, then the
resulting RE will match the second character.
\number Matches the contents of the group of the same number.
\A Matches only at the start of the string.
\Z Matches only at the end of the string.
\b Matches the empty string, but only at the start or end of a word
匹配一个空串但只在一个单词的开始或者结束的地方.匹配单词的边界
\B 匹配一个空串, 但不是在在一个单词的开始或者结束的地方.(匹配非单词边界)
\d 匹配一个数字字符。等价于 [0-9]。
\D 匹配一个非数字字符。等价于 [^0-9]。
\s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]。
\S 匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。
\w 匹配包括下划线的任何单词字符。等价于'[A-Za-z0-9_]'.
With LOCALE, it will match the set [0-9_] plus characters defined
as letters for the current locale.
\W 匹配\w的补集(匹配任何非单词字符。等价于 '[^A-Za-z0-9_]'。)
\\ 匹配一个"\"(反斜杠)