web2py

web2py auto_import vs define_table

时光毁灭记忆、已成空白 提交于 2019-12-09 08:15:28
The documentation we can use auto_import if we "need access to the data but not to he web2py table attributes", but this code seems to use the table attributes just fine. from gluon import DAL, Field db = DAL('sqlite://storage.sqlite', auto_import=True) for row in db(db.person).select(): print row.name The table was defined in a previous run. db = DAL('sqlite://storage.sqlite', auto_import=True) db.define_table('person', Field('name')) db.person[0] = {'name' : 'dave'} db.commit() Doing both auto_import=True and the define_table gives an error about "invalid table name". Doing neither gives an

web2py check password in form

别等时光非礼了梦想. 提交于 2019-12-08 12:00:55
问题 I am trying to create a change password form in web2py. I am using db.auth_user table. I want to create a form with fields ['current_password', 'new_password', 'repeat_password'] Form should give a warning to user if the password is not entered correctly. My code is: request.vars.current_password = request.vars.current_password if request.vars.current_password else 'xxx' user_password_form = SQLFORM.factory(Field('current_password', 'password', requires=IS_EQUAL_TO(db(db.auth_user.id == auth

What should I worry about Python template engines and web frameworks? [closed]

倖福魔咒の 提交于 2019-12-08 11:52:17
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I am a C# and ASP.NET MVC developer. I've completed some Python console applications but I am new to use Python for web applications.

Referencing a table in web2py before defining it

白昼怎懂夜的黑 提交于 2019-12-08 11:45:11
问题 My code is the following im trying to assign a department to employees and also create a manager in a department table db = DAL(lazy_tables=True) db.define_table('employee', Field('fullname','string',label='Name'), Field('email','string'), Field('phone','string'), Field('kids', 'string'), Field('phone', 'string'), #Field('date','datetime'), Field('dob', 'datetime', label='Date'), Field('department', 'reference department', requires=IS_IN_DB(db, db.department.id, '%(department_name)s')), auth

Web2py: downloading files / displaying images

北城以北 提交于 2019-12-08 10:00:51
问题 I've recently jumped into Web2py framework which I find very good. However, I'm now stuck with a 'basic' problem. Context The website I'm building is an interface for scientific code: people fills-in a form and submit it. The data (written in a file inside a shared folder) is then being processed by the code, running as a daemon in the background (the code has no link with the website, excepts this shared folder and a JSONRPC link between code->website ). The code generates files and images

can we use java code in web2py application code?

自作多情 提交于 2019-12-08 08:59:40
问题 I have to implement one web2py application which has to access java code (which has code to connect to the remote machine) but not sure whether we can do it in web2py or not.My PC has Java 1.6, Python2.7 ,web2py ,eclipse installed. Use case is : I have created one button in web2py application and upon clicking the button, it should instantiate the java object and invoke particular method of that java object which will further connect to the remote machine. Doubts are: Can we deploy that

web2py Ajax search

大憨熊 提交于 2019-12-08 07:24:30
I'm trying to use an ajax search slice for my website that I found here: http://www.web2pyslices.com/slices/take_slice/51 But for some reason I keep getting the error: IndexError: list index out of range Here is my version of the code: default.py (controller) def index(): listings = db().select(db.listing.ALL, orderby=db.listing.first_name) return dict(listings=listings, livesearch=livesearch()) def livesearch(): partialstr = request.vars.values()[0] query = db.listing.title.like('%'+partialstr+'%') listings = db(query).select(db.listing.title) items = [] for (i,listing) in enumerate(listings)

web2py: How to execute instructions before delete using SQLFORM.smartgrid

六月ゝ 毕业季﹏ 提交于 2019-12-08 05:04:24
问题 I use SQLFORM.smartgrid to show a list of records from a table (service_types) . In each row of the smartgrid there is a delete link/button to delete the record. I want to executive some code before smartgrid/web2py actually deletes the record, for example I want to know if there are child records ( services table) referencing this record, and if any, flash a message telling user that record cannot be deleted. How is this done? db.py db.define_table('service_types', Field('type_name',

web2py Ajax search

淺唱寂寞╮ 提交于 2019-12-08 05:00:44
问题 I'm trying to use an ajax search slice for my website that I found here: http://www.web2pyslices.com/slices/take_slice/51 But for some reason I keep getting the error: IndexError: list index out of range Here is my version of the code: default.py (controller) def index(): listings = db().select(db.listing.ALL, orderby=db.listing.first_name) return dict(listings=listings, livesearch=livesearch()) def livesearch(): partialstr = request.vars.values()[0] query = db.listing.title.like('%'

Reading file content from uploaded text file

陌路散爱 提交于 2019-12-08 04:15:45
问题 I have an uploaded file in uploads folder and i need to read the contents from it in the controller for processing it further. I have very basic knowledge of web2py and couldn't understand how to do it. 回答1: You can do something like: import os filename = db.mytable(record_id).myfile content = open(os.path.join(request.folder, 'uploads', filename), 'rb').read() UPDATE: Here is a somewhat simpler approach. 来源: https://stackoverflow.com/questions/26968216/reading-file-content-from-uploaded-text