pyramid

struck at sqlalchemy.exc.IntegrityError: (IntegrityError) constraint failed 'INSERT INTO users

感情迁移 提交于 2019-12-07 06:27:17
问题 I am using sqlite database and I declared the models as in this gist https://gist.github.com/mmahesh/7245561 I have added a model instance with transaction manager as with transaction.manager: model = Users(username='example',name='Example', email_primary='m@m.com', _password='example') DBSession.add(model) Whenever I execute initialize_sample_db development.ini, this error shows up sqlalchemy.exc.IntegrityError: (IntegrityError) constraint failed 'INSERT INTO users (name, username, email

uploading multiple files with pyramid

心不动则不痛 提交于 2019-12-07 01:52:43
问题 Trying to upload multiple files at once using python. The upload.html source code is as followed: <form name="frmRegister" method="post" accept-charset="utf-8" enctype="multipart/form-data" class="form-horizontal"> <div class="control-group"> <div class="controls"> <input type="file" name="files" multiple='multiple'> </div> </div> <div class="control-group"> <div class="controls"> <input class="btn btn-primary" type="submit" name="btnSubmit" value="Add Product" /> </div> </div> </form> in my

Multiple permissions in view_config decorator?

社会主义新天地 提交于 2019-12-06 23:07:16
问题 I am configuring access control for a web application based on the Pyramid framework. I am setting up permissions for my view callables using the @view_config decorator. I have two permissions, namely 'read' and 'write' . Now, I want certain views to require both permissions. I was unable to figure out how to do this with view_config - am I missing something, or is there maybe another way to do this? 回答1: Make a readwrite permission. Each view gets one and only one permission but each

Pyramid.security questions: Double cookies? Insecure cookies? Expiration?

China☆狼群 提交于 2019-12-06 23:04:53
问题 I'm taking my first foray into the Pyramid security module. I'm using this login code to set the auth_tkt: @view_config(route_name='LoginForm', request_method='POST', renderer='string') class LoginForm(SimpleObject): def __call__(self): emailAddress = self.request.params.get('emailAddress') password = self.request.params.get('password') if emailAddress != 'testemail@gmail.com' or password != 'testpassword': errorDictionary = { 'message' : "Either the email address or password is wrong." }

Password not getting encrypted when I update

我的梦境 提交于 2019-12-06 16:08:35
问题 Being a newb to python I am not quite sure why I am getting inconsistent results. I register a user and the password in my table ends up being the hashed version. When the user updates his password, the password in the table ends up being the unhashed version. Obviously, I want the hashed version. What am I doing wrong? (I am using SQLAlchemy and mysql if that matters.) I have the following: def hash_password(password): blah, blah, blah # hash my password here return hashed_password class

Creating Pyramid/SQLAlchemy models from MySQL database

感情迁移 提交于 2019-12-06 14:16:09
问题 I would like to use Pyramid and SQLAlchemy with an already existing MySQL database. Is it possible to automatically create the models from the MySQL tables. I do not want to write them all by hand. This could be either by retrieving the tables and structure from the Server or using a MySQL "Create Table..." script, which contains all the tables. Thanks in advance, Linus 回答1: In SQLAlchemy you can reflect your database like this: from sqlalchemy import create_engine, MetaData engine = create

How to check what permission failed in authorization in pyramid (pylons 2)?

拟墨画扇 提交于 2019-12-06 12:11:24
I add a view for the forbidden view: from pyramid.exceptions import Forbidden config.add_view(forbidden_view, context=Forbidden) which redirects to a log in screen. But now i added some admin things which needed admin access, and I want to just show a "you don't have the permission" screen, how do I check for that in the forbidden view? I'm afraid that information is lost when Pyramid raises a Forbidden error as the result of a permission denial. There's an item in the TODO.txt to carry it along through the Forbidden error. 来源: https://stackoverflow.com/questions/4916149/how-to-check-what

Running a Pyramid WSGI application under tornado

别说谁变了你拦得住时间么 提交于 2019-12-06 12:01:27
问题 Pyramid uses it's own Waitress web server for development purposes, but I want to serve my WSGI app under Tornado. I think I should configure it using the pserve .ini files, but I can't get it to work 回答1: The Pyramid application can be loaded from the INI files easily. From there you just pass the wsgi app into Tornado's WSGIContainer. from pyramid.paster import get_app app = get_app('development.ini') container = tornado.wsgi.WSGIContainer(app) 回答2: Again, not really recommending running

How to access image by url on s3 using boto3?

早过忘川 提交于 2019-12-06 09:43:55
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 can put it on an HTML, can I view it using the access and secret key?. Thank you for those who can

How to change the mako substitution delimiter characters?

守給你的承諾、 提交于 2019-12-06 08:29:54
问题 Is it possible to change the "delimiter tags" for expression substitution in the Python Mako templating library? If so, how? e.g.: Instead of <div>${foobar}</div> , I would like to use the syntax <div>{{foobar}}</div> . I can't seem to find any references in the Mako docs. 回答1: As of March 6, 2015, it's not currently possible . See the feature request to add configurable delimiters for Mako. 来源: https://stackoverflow.com/questions/28890953/how-to-change-the-mako-substitution-delimiter