do i need to declare my index.html in app.yaml? - python

I am new to google app engine and have trouble configure my web app. I don't know what i do need to add to app.yaml and what i don't? for example i know that i have to add my static files like images, and style sheets , but what about scripts files like angular do i need to declare them as static as well.
NOTE: APP STRUCTURE
+ProjectName
app.yaml
main.py
resources
images
styles
scripts
index.html
handlers:
- url: /rescources/images/(.*)
static_files: /images/\1
upload: /rescources/images/.*
- url: /rescources/styles
static_dir: /rescources/styles
- url: /rescources/scripts/.*
static_dir: /rescources/scripts
- url: /.*
script: main.APP
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest

Yes, your angular script files (if they are defined in a .js file) are to be considered static files. My suggestion is to move your images, css and script files (all .js files) into a seperate folder called 'static' and then your app.yaml file can be like below
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /static
static_dir: static
- url: /.*
script: main.APP
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
If there's the possibility that your static files might change more frequently (for e.g. you've deployed your code to production but you're still working and making changes, you might want to set an explicit but lower expiration date for your static files. The example sets an expiration of 2 hours for your static files
- url: /static
static_dir: static
expiration: "2h"
More details can be found here https://cloud.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Static_cache_expiration

Related

CSS not loading on gcloud app engine?

So, I'm trying to host a website on the google cloud app engine, but css and other static files are not showing up.
Here is the relevant directory structure:
myapp
-app.yaml
-manage.py
subapp
-apps.py
-models.py
-urls.py
-views.py
static
-style.css
And the relevant portion of app.yaml:
runtime: python
env: flex
api_version: 1
threadsafe: yes
handlers:
- url: /static
static_dir: static
- url: .*
script: myapp.wsgi.application
I would expect that when I go to https://myapp.appspot.com/static/style.css, they see the style.css file, but instead I get the 404 page not found error, and I see that gcloud compares the 'static/style.css' against the list of urls found in urls.py instead of the static directory specified in app.yaml.
What could be going wrong?
Sadly, static handlers do not work on the flexible environment. You should just serve your CSS the way you normally would from your python application.
You can try this in your app.yaml
handlers:
- url: /static/style.css
static_files: static/style.css
upload: static/style.css

Google App Engine Error at yaml_error

Following error as shown in screen-shot,occurs when i try to run my helloworld.py script in Google App engine from terminal.
#My Operating system:Ubuntu.14.#
And Here is my file app.yaml.
application: #My project Id.
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /static
static_dir: static
- url: /
static_files: static/index.html
upload: static/index\.html
secure: always
- url: /_ah/spi/.*
script: helloworld_api.app
libraries:
- name: endpoints
version: 1.0
The Problem is that i can't deploy my code on local machine.
Any helps would be Appreciated.Thanks :)
I had check Online Yaml parser and it shows its Valid too.
You're missing the libraries line, the endpoints library are actually interpreted as part of the handlers list, which is incorrect.
Should look like this:
...
- url: /_ah/spi/.*
script: helloworld_api.app
libraries:
- name: endpoints
version: 1.0

Google App Engine add image to page with static folder

i have a problem to use image with static folder path in my page.
this is my app.yaml
application: something
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /images
static_dir: static/images
- url: /favicon.ico
static_files: static/favicon.ico
upload: static/favicon.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
I have templates, static/images, controllers (has MainHandler.py) folders and in my root i have main.py and app.yaml files. in my templeate folder i have index.html file that contain:
<div>
<img src="images/fig1.jpg">
</div>
my problem is when page was loaded i cant see my fig1.jpg picture.
What is the url of this page? If it looks like a subdirectory, then your using a relative path for your image is not pointing to the images path. Try changing to:
<div>
<img src="/images/fig1.jpg">
</div>
If using Windows, there is a known bug. See:
Google App Engine: Won't serve static assets with below error:
Try adding mime_type: "image/jpeg" to your image handler, to see if that is the cause.

Static files not working on GAE

I'm using the following yaml configuration:
application: xxxxxxxx
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /bootstrap
static_dir: static/bootstrap
- url: /fonts
static_dir: static/fonts
- url: /js
static_dir: static/js
- url: /images
static_dir: static/images
- url: /css
static_dir: static/css
- url: /favicon\.ico
static_files: ./static/favicon.ico
upload: ./static/favicon\.ico
- url: /.*
script: main.app
libraries:
- name: django
version: "1.3"
And my folder structure is like this:
\
....static
..........bootstrap
...................css
...................js
...................img
..........css
..........fonts
..........images
..........js
In the development environment it works fine (using latest version available), but when I deploy the app it doesn't. I know the filenames are case sensitive on gae, but I've already checked that.
What else can be wrong?
Please Help.
Thanks
As stupid it may seems but removing the project from GAE Launcher and adding it back again and re-deploy it solved the issue.

Unable to include interactive python shell in flask app for GAE

I am using flask and the python 2.7 GAE SDK. I am trying to include an interactive shell, in my app.
I am trying to include the following interactive python shell in my app, so that I can interact with the GAE API while development - http://code.google.com/p/google-app-engine-samples/source/browse/trunk/shell/
As instructed I have copied the static/ and templates/ folders, and shell.py to the root of my app.
I have also added the url route ONLY to my app.yaml (shell)-
application: myflaskonappengineapp
version: 1
runtime: python27
api_version: 1
threadsafe: false
default_expiration: "5d"
builtins:
- appstats: on
- admin_redirect: on
- deferred: on
- remote_api: on
libraries:
- name: jinja2
version: "2.6"
- name: markupsafe
version: "0.15"
- name: lxml
version: "2.3"
- name: numpy
version: "1.6.1"
- name: PIL
version: "1.1.7"
- name: pycrypto
version: "2.3"
- name: setuptools
version: "0.6c11"
- name: webapp2
version: "2.3"
- name: webob
version: "1.1.1"
- name: yaml
version: "3.10"
inbound_services:
- warmup
handlers:
- url: /favicon.ico
static_files: application/static/img/favicon.ico
upload: application/static/img/favicon.ico
- url: /robots.txt
static_files: application/static/robots.txt
upload: application/static/robots.txt
- url: /_gae_mini_profiler/static
static_dir: packages/flaskext/gae_mini_profiler/static
- url: /static
static_dir: application/static
#interactive shell
- url: /shell
script: shell.py
- url: /remote_api
script: /opt/google_appengine/google/appengine/ext/remote_api/handler.py
- url: .*
script: application.app
However when I try to access the url /shell, I get a 404 error ? Do I need to configure flask also for routing ? Why is flask handling this url instead of shell.py?
You need to modify the shell.py to handle the URL '/shell' as well as app.yaml.
In particular, you need to edit the line 303 of the shell.py.
from
[('/', FrontPageHandler),
to
[('/shell', FrontPageHandler),
You also need to update your app.yaml like(add wildcard):
- url: /shell.*
script: shell.py
Please consider adding login:admin to the shell handler, otherwise you will open up the shell capability to everyone in the world.

Categories

Resources