web2py

web2py auto_import vs define_table

微笑、不失礼 提交于 2020-01-02 20:17:49
问题 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

How to change '_class' of Web2py autocomplete widget

会有一股神秘感。 提交于 2020-01-01 19:56:14
问题 I loop through a form object to change all the classes: form = crud.create(db.messages, next = URL('index')) parts = ['title', 'body', 'subject'] # corresponding fields classes = 'form-control col-md-12' # my classes for p in parts: form.custom.widget[p]['_class'] = '%s %s' % (classes, form.custom.widget[p]['_type']) This is working - but: subject is an autocomplete widget: db.messages.subject.widget = SQLFORM.widgets.autocomplete(...) and here _class is not changed (or altered afterwards

How do I deploy web2py on PythonAnywhere?

流过昼夜 提交于 2020-01-01 02:42:21
问题 How do i get a basic web2py server up and running on PythonAnywhere? 回答1: [update - 29/05] We now have a big button on the web tab that will do all this stuff for you. Just click where it says Web2Py , fill in your admin password, and you're good to go. Here's the old stuff for historical interest... I'm a PythonAnywhere developer. We're not massive web2py experts (yet?) but I've managed to get web2py up and running like this: First download and unpack web2py: wget http://www.web2py.com

web2py url validator

旧巷老猫 提交于 2019-12-31 04:13:14
问题 In a shorten-er built by web2by i want to validate url's first, if it's not valid goes back to the first page with an error message. this is my code in controller (mvc arch.) but i don't get what's wrong..!! import urllib def index(): return dict() def random_maker(): url = request.vars.url try: urllib.urlopen(url) return dict(rand_url = ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for x in range(6)), input_url=url) except IOError: return index() 回答1:

How to response with full range of data to GET request using web2py and python-requests

只谈情不闲聊 提交于 2019-12-25 16:24:32
问题 I'm very new to web2py and to web-requests so please keep a slack hand. I try to make application with web2py framework that allow me to do following: I send POST request to remote server (server's url, for example, is https://100.100.10.100 ) headers = {'Content-type': 'application/json'} payload = {"uuid": some_file.json, "level": "public", "Url": " http://localhost:8000/myApp/default/file_to_process} requests.post('https://100.100.10.100', data=json.dumps(payload), headers=headers) Server

web2py: how to detect when an LOAD component has loaded via ajax?

允我心安 提交于 2019-12-25 08:16:00
问题 I'm injecting a component into my web2py page using {{=LOAD(...)}} as described at http://web2py.com/books/default/chapter/29/12/components-and-plugins#LOAD, but I need to fire off some javascript once the component is loaded. Normally if something is loaded via ajax, there is a success callback. How can I set one of this via {{=LOAD(...)}} in web2py? 回答1: The simplest approach would be to set response.js in the controller of the component: def mycomponent(): response.js = 'alert("mycomponent

request.vars.variablename gives empty string instead of None

雨燕双飞 提交于 2019-12-25 07:24:31
问题 I am using SQLFORM.factory to create a custom form. In this form I have a field as: Field('useraccount','unicode',default=None) So as per my understanding, when user does not supply this value, request.vars.useraccount will be None. But it rather shows empty string value. I can convert it to None by checking for empty string value but I do not want to do that. Please suggest me any solution. 回答1: When the form is submitted, if the "useraccount" input field is empty, the browser still sends an

web2py rest api endpoint gives invalid path output

烂漫一生 提交于 2019-12-25 07:09:23
问题 I have made a web2py web application. The api endpoints exposed are as follows. "/comments[comments]" "/comments/id/{comments.id}" "/comments/id/{comments.id}/:field" "/comments/user-id/{comments.user_id}" "/comments/user-id/{comments.user_id}/:field" "/comments/date-commented/{comments.date_commented.year}" "/comments/date-commented/{comments.date_commented.year}/:field" "/comments/date-commented/{comments.date_commented.year}/{comments.date_commented.month}" "/comments/date-commented/

How to preselect options in SELECT helper in web2py

ε祈祈猫儿з 提交于 2019-12-25 04:33:10
问题 when creating multiple select input with SELECT, OPTION helpers, I want to preselect some options, I tried following OPTION('myOption', _value=val, value=[v1, v2]) extrapolating from the docs, but it does not work 回答1: "value" is an attribute of the "SELECT" helper. From the documentation : web2py make a distinction between "_value" (the value of the OPTION), and "value" (the current value of the enclosing select). If they are equal, the option is "selected". http://www.web2py.com/books

Web2py's 'contains' function for 'instr' function of mysql

余生长醉 提交于 2019-12-25 03:19:39
问题 I have this mysql query which works fine for me select * from mc,mcex where instr(mcex.example,mc.element) I have written following code in web2py for this as given below: rows=db(db.mcex.example.contains(db.mc.element)).select() Its not working. Please help. 回答1: Using the web2py DAL, the query (which generates the SQL WHERE clause) can simply be a string of SQL code, so you can do: rows = db('instr(mcex.example, mc.element)').select(db.mcex.ALL, db.mc.ALL) UPDATE: If you need a conjunction