Menu
  • HOME
  • TAGS

How to do SEO Url changes and Redirects for google AppEngine Webapp2 Urls?

python,google-app-engine,webapp2

You could first catch ALL requests to the "www" subdomain: from webapp2_extras.routes import DomainRoute app = webapp2.WSGIApplication([ DomainRoute('www.domain.com', [ webapp2.Route(r'/<:.*>', handler=RedirectWWW), ]), ('/', IndexPage), ('/discover', DiscoverPage), ('/about', AboutPage), ('/help', HelpPage), ('/terms-and-privacy', TermsPage) ], debug=True) with a handler that replaces the www part with the naked domain: class RedirectWWW(webapp2.RequestHandler): def get(self,...

Uploading Files in webapp2/GAE

python,google-app-engine,blobstore,webapp2

The content of uploaded files is in self.request.POST in your handler, so you can get that content (assuming e.g the field for the uploaded file is named 'foo') with e.g content = self.request.POST.multi['foo'].file.read() So now you have the content as a string -- process it as you wish. This does...

app engine update all sessions for user

google-app-engine,webapp2,gae-sessions

I think storing in database and doing a query on each request is the most natural option. Don't know about your full requirements and specifications, but for keeping the sessions synchronized I think a solution like firebase makes a lot of sense, though it might be overkill in your case....

How do I get the parent entity in GAE?

python,google-app-engine,datastore,webapp2

You can get a key of a parent entity from the key of your child entity. Look at the key Class: https://developers.google.com/appengine/docs/python/datastore/keyclass#Key_parent...

Instantiating WSGIApplication in webapp2

python,webapp2

webapp2 does some magic on routes (converting from the tuples to webapp2.Route instances). When you just assign to routes, it won't work because they haven't been converted to the right format for webapp2. I believe you can just add in the Route instantiation and it should work.

How does python inheritance work with GAE?

python,google-app-engine,inheritance,webapp2

Try changing: class BlogHandler(webapp2.RequestHandler): def __init__(self, request=None, response=None): self.is_logged_in = False super(BlogHandler, self).__init__(request, response) Putting your attribute before your call to super....

GAE Python unable to write file properly to Cloud Storage

python,google-app-engine,google-cloud-storage,webapp2

enctype is an attribute of the form tag: <form action="/upload_data" method="post" enctype="multipart/form-data"> <input type="file" name="add_scanned_data_file"> <input type="image" src="stylesheets/add_data.png" alt="submit" align="left"> </form> ...

how to upload image using google cloud client library on cloud storage in python?

python,google-app-engine,google-cloud-storage,webapp2

def CreateFile(filename,imageFile): with gcs.open(filename, 'w', content_type = 'image/jpeg') as f: f.write(imageFile) f.close() blobstore_filename = '/gs' + filename return blobstore.create_gs_key(blobstore_filename) class MyImageHandler(webapp2.RequestHandler): def post(self): bucket='youbucketname' imageFile = self.request.get('file') nameOfFile = self.request.get('filename1') fileName = '/youbucketname' + '/' + nameOfFile blob_key = CreateFile(fileName, imageFile) imageUrl = 'https://%(bucket)s.storage.googleapis.com/%(file)s' %...

GAE webapp2 delete all UserTokens (drop all sessios) for specific user

python,google-app-engine,webapp2

I see two ways how to do that. First is to inherit from the UserToken class making user an indexed property. Then you can set the token_model class property to your new token model in your user class. Here is the code: class MyToken(UserToken): user = ndb.StringProperty(required=True) class MyUser(User): token_model...

HTTP DELETE with HTML

python,html,html5,http,webapp2

Short answer: The issue is not with the web framework or the browser. This is an HTML limitation. HTML only allows for GET and POST. No other methods are permitted. I've adjusted my title to reflect the subject matter more accurately. More details: Based on the HTML clue from @Greg,...

how to display images from the ndb datastore using data URI scheme (via passing data to template and not having to make another request)

python,image,google-app-engine,app-engine-ndb,webapp2

Use the image service and the images will be served from a high speed image serving service that'll probably be closer to your end users in any case then anything you could arrange yourself in GAE. https://developers.google.com/appengine/docs/python/images/functions get_serving_url(blob_key, size=None, crop=False, secure_url=None) Returns a URL that serves the image. This URL...

Gae webapp2 routing problems. match the uris wrong

google-app-engine,url-routing,webapp2

Route like '/users/' will catch all requests on '/users/*', so you can fix your problem by changing the order of routes: _route = [ RedirectRoute('/', 'home.HomeHandler', name='home', strict_slash=True), RedirectRoute('/users/comments/new/', 'users.UserNewCommentHandler', name='new-comment', strict_slash=True) RedirectRoute('/users/<usercode>', 'users.UserSingleHandler', name='user-page', strict_slash=True), ] ...

How to serve a pdf as a download programmatically in GAE and Webapp2?

google-app-engine,pdf,webapp2

Your mypdf.pdf is not set up as application readable. You can do that in app.yaml - url: /mypdf.pdf static_files: mypdf.pdf upload: mypdf.pdf application_readable: true ...

Using App Engine Cloud Endpoints to access ndb datastore

python,google-app-engine,google-cloud-endpoints,webapp2,google-datastore

Yes, that's a perfectly reasonable approach. If you are using Cloud Endpoints and NDB, you may want to look at the Endpoints Proto Datastore API which takes some of the legwork out of serializing your NDB Model entities. Personally, I didn't find the API very intuitive so I reverted to...

Google app engine: fetching a lot of urls and data processing

python,google-app-engine,python-2.7,webapp2

You can control execution time in queue.yaml, by setting rate to 10/s for example. Be sure that your module configuration is set to auto scaling, or use proper manual scaling. queue: - name: default rate: 5/s Also take a look into your logs and look for failing tasks, which could...

Using Google App Engine Property's verbose_name in jinja2

python,google-app-engine,jinja2,webapp2

For starters, the purpose of verbose_name is to use it in the label, not as the name of the input. It's better if the name matches the model (for clarity and future automation), and I don't think it'll change often (if at all), because that requires a lot of work...

How should I store an entity key in a webapp2 session?

google-app-engine,session,webapp2

Use a urlsafe version of the key: https://cloud.google.com/appengine/docs/python/ndb/entities#retrieving_entities self.session['client'] = client.key.urlsafe() On retrieval, use client = ndb.Key(urlsafe=self.session['client']).get() ...

GAE User Authentication using python, webapp2, ndb

python,google-app-engine,authentication,gae-datastore,webapp2

You should look into managing sessions in webapp2. Basically what need to happen is, user1 has to login, and you'll store the login info (eg user id) in the session. Whenever the url www.example.com/ViewFriendsFruits?id=user2id is hit, you'll want to check if there is currently user logged in (by checking the...

GAE NDB: Calculating and displaying entity's view count efficiently

google-app-engine,python-2.7,jinja2,app-engine-ndb,webapp2

Counter information is persistent, you don't have another option than writing it to datastore. For a more efficient and fast implementation i would invite you to check out Sharding counters...

Redirect old website urls in new GAE/Python/webapp2 website

python,regex,google-app-engine,url-redirection,webapp2

Change the order of the rules and you should be fine. Later on, when you'll see that nobody is actually visiting the old URLs you could just delete this handler. app = webapp2.WSGIApplication([ ('/', Home), ('/get/something', AnotherHandler), ('/(.+)/?', oldPathsHandler), ], debug = True) ...

Export js file for users

javascript,json,laravel,amazon-s3,webapp2

Simple answers such as which frameworks, tools etc to use is more than fine. Willing to learn! ;) Your question is too general, there isn't a one right way or a framework/tools that does this task better/worse than others, it just depends on how you want and how you...

How to redirect user to previous page when Logout?

python,google-app-engine,cookies,logout,webapp2

The browser usually sends along the page the user came from, with the HTTP Referer (sic) header. Because of privacy concerns, not all browsers send this, or they may falsify it or only send if the next page requested is in the same domain. But it is still the most...

ImportError: No module named SQLAlchemy. GAE and webapp2

python,google-app-engine,sqlalchemy,importerror,webapp2

On you local machine you have sqlalchemy installed. On appengine you don't have it thats why your import is failing.

How to upload an image from client side form to Google cloud storage bucket?

html,google-app-engine,python-2.7,google-cloud-storage,webapp2

from __future__ import with_statement import cloudstorage as gcs import webapp2 import logging from google.appengine.ext import blobstore from google.appengine.ext.webapp import blobstore_handlers def CreateFile(filename,imageFile): with gcs.open(filename, 'w', content_type = 'image/jpeg') as f: f.write(imageFile) f.close() blobstore_filename = '/gs' + filename return blobstore.create_gs_key(blobstore_filename) class MyImageHandler(webapp2.RequestHandler): def post(self): bucket='yourbucketname' imageFile = self.request.get('file')...

Is there a way to map GAE user object and Google+ userid

python,google-app-engine,webapp2

Yes, using their user.email() To access properties of their Google+ profile you will need to use the Google APIs Client Library for Python https://developers.google.com/api-client-library/python/start/installation...

How to construct and store the geopoint

google-app-engine,twitter-bootstrap-3,geolocation,webapp2,geopoints

input_geopoint= GeoPoint(input_latitude, input_longitude) NameError: global name 'GeoPoint' is not defined. Am getting this error You're getting that error because you don't have the module imported where GeoPoint is defined. Add this import from google.appengine.api import search and then use like this input_geopoint = search.GeoPoint(input_latitude, input_longitude) Also see the docs...

GAE/webapp2: Serving Excel file created by script using xlwt

python,google-app-engine,webapp2,xlwt

Here's a "hello world" (!) GAE handler trying to do the kind of thing you're talking about: this is main.py, to which app.yaml routes all URLs; I've copied xlwt/*.py into the subdirectory xlwt of the directory in which main.py and app.yaml live. import webapp2 import StringIO import xlwt def makeit():...

Google appengine memcache scope

python,google-app-engine,webapp2

Memcache instance is global and not tight to the User instance. You add values to memcache by key, so you can implement User bound memcache on your own, by using user key + some additional info as key to memcache value. memcacheService.put(userKey + "userBalance", userBalance); This will cache userBalance per...

Webapp2 Redirect Method

python,google-app-engine,webapp2

Use a 307 redirect. A 307 will not change the method of the redirect. Wikipedia: 307 temporary redirect (provides a new URL for the browser to resubmit a GET or POST request)...

Python : Cannot find any functions within my own module?

python,python-2.7,module,attributes,webapp2

You have a package mymodule, containing a module mymodule. The function is part of the module, not the package. Import the module: import mymodule.mymodule and reference the function on that: mymodule.mymodule.testmod() You can use from ... import and import ... as to influence what gets imported exactly: from mymodule import...

Comma in json string causes json.loads to fail with “Unterminated string starting at:”

python,json,google-app-engine,python-2.7,webapp2

You are sending in your request a list, not a string events=[{"event":"reset", "test":"reset;123"}] you should use '{"events":[{"event":"reset", "test":"reset;123"}]}' ...

RBAC in webapp2 with ACL from tipfy

google-app-engine,webapp2,rbac,tipfy

At the end I find out that area can be anything you want and it's up to you what meaning it has. Just define a property in your handler that return some string ... and that's the area. Also ... I Finally end up coding a RBAC for google app...

Python Google App Engine. GET Request sent twice

python,google-app-engine,jinja2,blobstore,webapp2

Your question is missing critical information, how are the routes set up, where's the template code? The problem obviously comes from the client, where else could the request come from? You should be providing information on that front. Anyway, for some weird reason I think I might know what it...

How do I pass multiple variables from one handler to another in GAE?

python-2.7,google-app-engine,jinja2,webapp2

The pattern you're trying to write doesn't work within http, irrespective of what backend platform or language you're using. Your HTML is posting to the server and the GAE code is handling the post. At that point in the interaction, the browser has already submitted and is awaiting a response...

Google App Engine: store uploaded file in Google Cloud Storage

python,google-app-engine,webapp2

I've successfully POST'ed a file to GCS with the following method: def post(self): write_retry_params = gcs.RetryParams(backoff_factor=1.1) filename = '/{MY-BUCKET-NAME}/static.txt' gcs_file = gcs.open( filename, 'w', content_type='text/plain', options={'x-goog-meta-foo': 'foo', 'x-goog-meta-bar': 'bar'}, retry_params=write_retry_params) inFile = self.request.POST.multi['file'].file while 1: line = inFile.readline() if not line: break gcs_file.write(line) logging.info('Wrote line: {}'.format(line)) gcs_file.close() Here's the little...

Pass variables in AngularJS $http GET?

javascript,python,angularjs,google-app-engine,webapp2

Yes, just add it onto the url: $http.get("/users?items=15").success(function(data) { $scope.users = data; }); Then in your python handler for /users get the value of items using self.request.get("items")...

CSS Files not working on localhost

html,css,google-app-engine,twitter-bootstrap,webapp2

For PIL, add this to the libraries section of app.yaml: - name: PIL version: latest To diagnose the 500 error in your css request, try adding this: - url: /static/css static_dir: static/css mime_type = "text/css" (This needs to be ABOVE your - url /static call, so it runs first...

Cant Save relational Entities in breezejs

angularjs,entity-framework-6,breeze,webapp2

You need to map the orderId foreign key property of the OrderDetail and DifferentDetail entities. When Breeze sends the entities to the server, it communicates the relationship between entities using the foreign keys.

Backbone - receiving DELETE data in the back end

javascript,backbone.js,webapp2

My problem was that I was defining the url attribute in BOTH the model AND the collection. You should only define url in the collection. Stupid mistake.

App Engine: How can I give an image response using self.response.out using the webapp2 framework?

google-app-engine,webapp2

Do the work, then redirect to location of the image. # do work self.redirect('/static/image.gif') Alternatively, set the Content-Type to the mime type matching the image, then open the image as a file and write it. A bit more work on the program side, but it saves the extra round trip...

How to compare posted webapp2 value to string in a form using %{name}s python

python,python-2.7,python-3.x,webapp2

I dont know webapp2, but 10 is the length of %(status)s. Correct would be val = str(status) as the 1st line, I think. Or simply check for status == XX