pyramid

Generic incoming file upload http request object for all python frameworks [closed]

一曲冷凌霜 提交于 2019-12-23 17:30:48
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I am working on a SDK that validates and saves incoming multipart/form-data files to disk on the server side. Something like: sdk.upload(httpRequest, destinationPath, validationOptions) I need the incoming http request for: field name, file name, file and mime type. The problem is

Pyramid on App Engine gets "InvalidResponseError: header values must be str, got 'unicode'

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 13:32:28
问题 I am using Pyramid 1.3 with the AppEngine 1.6.4 SDK on OS X 10.7.3. I am using Python 2.7 and have threadsafe true in app.yaml. @view_config(route_name='manager_swms', permission='manager', renderer='manager/swms.jinja2') def manager_swms(request): """Generates blobstore url and passes users swms in swms table""" # generate url for any form upload that may occur upload_url = blobstore.create_upload_url('/upload_swm') user = get_current_user(request) swms = DBSession.query(SWMS).filter_by

How to get an actual Pyramid request when unit testing

余生长醉 提交于 2019-12-23 11:55:21
问题 I have a Pyramid app that I'm still trying to learn. I'm supposed to write unit tests for it but I don't know how to build a request. I see that Pyramid has a test module with a DummyRequest but this is blank and obviously if I pass that into the views it will fail because it's not populated with the attributes that the request would have while running. So the question is, how to I pass a request that looks like a run-time request while testing? 回答1: The thing to realize whenever you are unit

Mako escaping issue within Pyramid

点点圈 提交于 2019-12-23 09:38:14
问题 I need to put javascript function to mako template. The first argument of this function is string, so I write in my *.mako file (dict(field_name='geom')): init_map( '${field_name}' ); But when I see my html page it loks like: init_map( 'geom' ) How I can disable escaping in this case? Rendering performs the following way: from pyramid.renderers import render render('georenderer/map.mako', template_args) 回答1: You'll need to include the quotes in your expression I think. You can use the json

Pyramid app: How can I pass values into my request.route_url?

ぃ、小莉子 提交于 2019-12-23 04:54:17
问题 I have this in my views.py file as the view config for my home page: @view_config(route_name='home_page', renderer='templates/edit.pt') def home_page(request): if 'form.submitted' in request.params: name= request.params['name'] body = request.params['body'] page=Page(name,body) DBSession.add(page) return HTTPFound(location=request.route_url('view_page',pagename=name)) return {} Also, here is the form in the edit.pt template: <form action="/view_page" method="post"> <div> <input type="text"

Run code at Pyramid shutdown

不羁的心 提交于 2019-12-23 04:38:12
问题 Pyramid supports an ApplicationCreated event. However I can't find any ApplicationDestroyed / ApplicationShutdown event. Is it at all possible do execute a function upon shutdown. Do I have any choice other than to go further up my stack: ie. I'm using gevent inside uWSGI. It might be possible to get gevent or uWSGI to run my shutdown code, but it certainly isn't as pretty. 回答1: Pyramid does not support any shutdown event. However Python has a atexit event, that runs on interpreter shutdown

In Pyramid Framework what is the difference between default Unencrypted Session Factory and setting cookies manually?

给你一囗甜甜゛ 提交于 2019-12-23 02:24:05
问题 I do not understand the difference between setting up a Unencrypted Session Factory in order to set cookies, as compared to using request.response.set_cookie(..) and request.cookies[key] . 回答1: The UnencryptedCookieSessionFactory manages one cookie, that is signed . This means that the client can read 1 what is in the cookie, but cannot change the values in the cookie. If you set cookies directly using response.set_cookie() , the client can not only read the cookie, they can change the value

How to access image by url on s3 using boto3?

久未见 提交于 2019-12-22 18:37:36
问题 What I want to accomplish is to generate a link to view the file (ex.image or pdf). The item is not accessible by URL (https://[bucket].s3.amazonaws.com/img_name.jpg), I think because its private and not public? (I'm not the owner of the bucket, but he gave me the access_key and secret_key?) For now, all I can do is to download a file with this code. s3.Bucket('mybucket').download_file('upload/nocturnes.png', 'dropzone/static/pdf/download_nocturnes.png') I want to access an image on s3 so I

Route requests based on the Accept header in Python web frameworks

感情迁移 提交于 2019-12-22 11:29:40
问题 I have some experience with different web frameworks (Django, web.py, Pyramid and CherryPy), and I'm wondering in which one will it be easier and hopefully cleaner to implement a route dispatcher to a different "view/handler" based on the "Accept" header and the HTTP method e.g.: Accept: application/json POST /post/ is handled different than: Accept: text/html POST /post/ So the request gets routed to the particular view of the corresponding handler of the MIME "application/json" and the HTTP

IntegrityError: ERROR: null value in column “user_id” violates not-null constraint

左心房为你撑大大i 提交于 2019-12-22 09:24:32
问题 Using: postgres (PostgreSQL) 9.4.5 I just migrated a sqlite3 db onto a postgresql db. For some reason since this migration, when I try to create a user, an error regarding the user_id (which is a primary key) is being raised. This was not an issue before with sqlite3 . I have spent time looking through the docs and stack questions, but remain confused. Inside api.create_user() : api.create_user(username ='lola ', firstname ='cats ', lastname ='lcatk', email='cags@falc.com') sqlalchemy db