web2py

Repetition of data for import_from_csv_file() in web2py for sqlite database table

喜你入骨 提交于 2019-12-12 00:34:49
问题 I want to load data from csv file into SQlite database. My code is : Model: db.define_table('data_table', Field('Title',requires =IS_NOT_EMPTY()), Field('Link',requires =IS_NOT_EMPTY())) db.data_table.import_from_csv_file(open('mycsv'),'rb') Controller: def index(): query=((db.data_table.id)) fields = (db.data_table.id, db.data_table.Title, db.data_table.Link) headers = {'data_table.id': 'ID', 'db.data_table.Title': 'Title', 'db.data_table.Link': 'Link', } default_sort_order=[db.data_table.id

How to set response Content-Length to infinite

二次信任 提交于 2019-12-11 23:55:48
问题 I try to create an application in web2py framework. By default web2py server has Transfer-Encoding: Chunked header for response, but in that case when target remote web application sends GET request to my app it could get only first string of text from requested page (from file's content that displayed on page). If to use Content-Length instead, for example, with value of 1000 it will get 1000 bytes of data from page... But if I expect to response with huge range of data, how to set Content

How can I join 3 tables and output all three together joined in web2py?

南楼画角 提交于 2019-12-11 22:40:14
问题 model: # coding: utf8 db.define_table('dept', Field('name',unique=True,label='Department Name'), format='%(name)s') db.define_table('course', Field('dept_id','reference dept'), Field('name',unique=True,label='Course Name'), format='%(name)s') db.define_table('files', Field('course_id', 'reference course'), Field('documentx','upload')) controller: def show_doc(): rows = db( db.course.id == db.files.course_id , db.dept.id==db.course.dept_id).select() return rows What I am trying to do is to

Why do I get this error: form2 not defined

随声附和 提交于 2019-12-11 19:35:31
问题 My code: def return_post: form = SQLFORM(db.post) for c in form: form1= post.body form2 = form1.split() return dict(form2=form2) In view: {{=form2}} I get the error that form2 is not defined. The above is the actual code. I had actually posted this from the Samsung tab and could not get the curly brackets. 回答1: You have to use =form2 within curly braces, not parenthesis. {{=form2}} Change it and try again. If using your tablet, try copy-pasting the above line. That should work. 来源: https:/

How to set default orderby in a web2py table?

白昼怎懂夜的黑 提交于 2019-12-11 19:05:46
问题 Although I consider this a simple task I can't find a way to make it work when using a SQLFORM . Let's say I have this structure as an example: db.define_table('month', Field('name', 'string'), format='%(nombre)s' ) db.define_table('foo' Field('bar', 'string'), Field('month', db.month), # I want to sort this by ID format='%(bar)s' ) db.month.update_or_insert(id=1, nombre='January') db.month.update_or_insert(id=2, nombre='Frebruary') # ... db.month.update_or_insert(id=12, nombre='December') In

web2py: Replace Smartgrid standard delete button

爷,独闯天下 提交于 2019-12-11 16:53:52
问题 I wanted to replace the standard delete button in Smartgrid. Here's what I attempted to do: def list_service_types(): grid = SQLFORM.smartgrid(db.service_types , fields = [db.service_types.type_name, db.services.service_name] , ondelete = ondelete_service_type , links = [lambda row: A('Delete', _href='#', _glyph="icon-trash", _class="button btn btn-secondary", )] ) return locals() Problems: 1) I can't get the icon-trash glyph/icon to display 2) How do I position the new button at the end of

web2py insert value into session

淺唱寂寞╮ 提交于 2019-12-11 13:39:46
问题 I am having problems with session After a user selects smth from drop down menu I have to insert that value to session. I need that value to get to the database for auth tables in model (it crashes when I go to login/register form if I read from request.var). Where do I insert the value in session and how (view, controler). For now I solved it using cookies but it is not the most secure. Any suggestions= thank you 回答1: session is another instance of the Storage class. Whatever is stored into

web2py custom 404 page when I raise the 404 myself?

半腔热情 提交于 2019-12-11 12:56:22
问题 I have a function in my controller that take an HTTP GET request. On certain argument values of that request I want to raise a 404. I also want that 404 to get rerouted to a different html page that I can make instead of giving that generic 404 NOT FOUND or whatever with a message. I made a routes.py which is in the root directory of my application and it contains routes_onerror[('myapp/404', 'myapp/static/404.html')] And I also have a 404.HTML in my static folder. Is what I am trying to do

insert some tuples into table in web2py

谁说我不能喝 提交于 2019-12-11 11:26:38
问题 I want to import csv file into auth_user table without duplicate username,so I create table user db.define_table('user', Field('username',unique=True,length=255), Field('password')) import csv file into user then compare table user and auth_user, insert some records that in user table while not in auth_user table. db.executesql('insert into auth_user(username,password) select username,password from user where not exists(select * from auth_user where (auth_user.username=user.username))') it

angularJS & web2py: calling python from ng/javascript/html

删除回忆录丶 提交于 2019-12-11 11:17:17
问题 I'm using AngularJS (mainly the client side) and web2py (mainly the server side)together in an app. I have an issue now. At a point of the program, I use AngularJS to get some data from the client and these data are store in an AngularJS variable. I planed to use $http.post to submit these data to database directly, but it didn't work due to cross-orign problem. Right now I'm trying to pass these data(they are in JSON format) back to web2py and let web2py insert these data to database.