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
Related
here is my directory structure:
Worker/
worker.py
worker.yaml
SharedCode/
sharedMoudle1.py
sharedMoudle2.py
...
in the worker.py , I want to include code from the shared folder. obviously in my local computer, it works since I have the Directory.
How Do I configure the worker.yaml to deploy the SharedCode directory together with sharedCode??
here is my worker yaml
runtime: python27
api_version: 1
threadsafe: true
vm: true
service: worker
env_variables:
PYTHON_ENV: lab
network:
instance_tag: testing
name: olympus-dev
handlers:
- url: /.*
script: worker.app
login: admin
p.s not using the the sharedCode , the worker works fine
Your need to convert your directories to python modules (by adding an __init__.py file), and then place the .yaml file in your project root directory. Your final directory structure should look similar to this:
worker.yaml
worker/
__init__.py
worker.py
sharedcode/
__init__.py
sharedmodule1.py
sharedmodule2.py
Then edit the handlers directive in your yaml, as follows:
handlers:
- url: /.*
script: worker.worker.app
login: admin
Here's an example on how to import code from the shared module:
from sharedcode.sharedmodule.py import *
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
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.
I have Google App Engine and Python running on http://localhost, which is fine working. But for making it reliably working i need to add https, Google App Engine do not have it.
So i have been trying stunnel and apache to make https working. I tried following but its still not working.
NameVirtualHost example.stackoverflow.com:443
<VirtualHost example.stackoverflow.com:443>
SSLEngine on
SSLProxyEngine On
ProxyPreserveHost On
#ProxyRequests Off
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/stunnel/a.crt
SSLCertificateKeyFile /etc/stunnel/a.key
SSLCertificateChainFile /etc/stunnel/b.ca
ServerName localhost
ProxyPass / http://localhost
ProxyPassReverse / http://localhost
#ProxyPassReverseCookiePath /MYSITE/ /
CacheDisable *
</VirtualHost>
when a user visit: https://example.stackoverflow.com, basically his browser address get changed from https:// to http://example.stackoverflow.com and he is able to use the Google App Engine and Python instances.
But i need to have https for Google App Engine with my python. How can i resolve it please?
EDIT: secure is used but still not working
application: rtc
version: 6
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /html
static_dir: html
- url: /images
static_dir: images
- url: /js
static_dir: js
- url: /css
static_dir: css
- url: /.*
script: rtc.app
secure: always
inbound_services:
- channel_presence
libraries:
- name: jinja2
version: latest
Google App Engine does support HTTPS, you just need to sign up for it. It is not free, but it isn't too expensive either.
More information on the types of SSL provided is available at: SSL for a Custom Domain.
Also, if you want to automatically redirect users to the secure site, you can use the secure keyword in Google App Engine's app.yaml configuration file. See Secure URLs.
I'm working on my first GAE project and I'm having some trouble getting custom pages to show up in the Admin Console. I'm following the Google Docs on it, but it doesn't seem to be working for me. I have a feeling it could have something to do with this note:
Note: Only custom pages defined by the default version will be shown
in the Admin Console.
but I'm not entirely sure what they mean (the default version of the app?).
The page URLs work fine if I visit them directly, but the links will not show in the Admin Console sidebar.
YAML:
application: namegenerator
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /css
static_dir: css
- url: /admin/.*
script: main.app
login: admin
- url: /.*
script: main.app
libraries:
- name: jinja2
version: latest
builtins:
- remote_api: on
admin_console:
pages:
- name: Manual DB Entry
url: /admin/db/add
- name: Clear DB
url: /admin/db/clear
Python routing:
app = webapp2.WSGIApplication([('/', MainHandler),
('/vote', SubmitVote),
('/clear_session', ClearUserSession),
('/admin/db/clear', ClearDatabase),
('/admin/db/add', ManualAddToDatabase)],
debug=True)
This is all being tested and run on my local machine, by the way. Thanks for any help.
Your code looks fine to me. Did you deploy your application? I think the admin pages will not be shown in your SDK.
By the way: An administrator can change which major deployed version of the application is default using Administration Console: https://appengine.google.com/