I recently deployed a website for my dad using Google App Engine.
Oddly, some images in the gallery are found, while some return with a 404. I looked in the admin dashboard for usage rates, and it says I'm only at 17% of "Code and Static File Storage".
I have tried changing the directory and re-deploying, I have also created a second application (from this-site-1 to this-site-2), and I have waited about an hour in case it's simply the cache, but none of these seem to be the issue.
I'm brand new to Google App Engine, this is the first website I've deployed using it, so any help would be much appreciated.
app.yaml
application: this-site-2
version: 1
runtime: python
threadsafe: true
api_version: 1
handlers:
- url: /robots.txt
static_files: static/robots.txt
upload: static/robots.txt
- url: /css
static_dir: static/css
- url: /img
static_dir: static/img
- url: /js
static_dir: static/js
- url: /.*
script: main.py
Edit: I updated python to 2.7 in case that was the problem, but I did by doing this:
application: this-site-2
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /robots.txt
static_files: static/robots.txt
upload: static/robots.txt
- url: /css
static_dir: static/css
- url: /img
static_dir: static/img
- url: /js
static_dir: static/js
- url: /.*
script: main.app # a WSGI application in the main module's global scope
libraries:
- name: webapp2
version: "2.5.1"
- name: django
version: "1.2"
skip_files:
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?index\.yaml
- ^(.*/)?index\.yml
- ^(.*/)?#.*#
- ^(.*/)?.*~
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*/RCS/.*
- ^(.*/)?\..*
- ^(.*/)?.*\.bak$
- ^(.*/)?.*\.less$
Then I deployed, and the console said that the deployment was successful and it was updating the indexes and exited with code 0. Then I tried to go to the website and it returned with a 500 server error. So I downgraded back to python 2.5 and the site is fine.
I think your image url handler is more complicated than it needs to be. I would suggest:
Put all static content (images, Javascript, CSS) in a folder called static or similar with subfolders for images, Javascript and CSS.
Use the following handler instead of your current image handler:
handlers:
- url: /images
static_dir: static/images
All files in the static/images folder will then be accessible on the url yourwebsite.com/images/subpath/image.jpg.
For more inspiration, see this app.yaml.
I had this problem and it turned out that it deploying images with lower case file extensions like this: name.png, but not ones with capital file extensions like this: name.PNG. Helpfully Windows hides this from you, so you can't always tell.
Ah, my dad solved it;
Simply change the jpg images that aren't working to a png image (and vice versa, if it's a png image not working, convert it to a jpg)
Related
I am Trying to make a simple website with a image in it by using google app Engine. I am unable to make it.
My App.yaml code is below:
application: simplegraph-007
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /image/.*
static_dir: static/image/.*
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
My Main.py looks like:
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write("<img src ='/image/Ris.jpeg'/>")
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
My log is here:
INFO 2015-10-19 18:46:39,111 module.py:786] default: "GET /image/Ris.jpeg HTTP/1.1" 404 154
I hope to have help from you.
Thanks,
You can serve static images like this.
In app.yaml
- url: /image
static_dir: image
In your app root folder, create a folder /image and put Ris.jpeg there.
Folder layout should look similar to this
+ image
|
-- Ris.jpeg
- app.yaml
- main.py
GET /image/Ris.jpeg will now return the image file.
Also see the docs.
Check your logs when you start your app locally. I am sure it is printing an error. This is invalid for static_dir
- url: /image/.*
static_dir: static/image/.*
It does not need a wildcard. It should read:
- url: /image
static_dir: static/image
Your image in your local filesystem should be static/image/Ris.jpeg.
I'm having some trouble creating a Google App Engine Cron task for my Web2Py application. I've looked at the instructions for GAE Cron, and this is the task I created as a test:
my cron.yaml file is in the same directory as my app.yaml,
the path to my python controller is applications/data/default, and
the url to access the function is myapp.appspot.com/data/default/test.
This is my cron task entry:
cron:
- description: test
url: data/default/test
schedule: every 2 minutes synchronized
however, I'm getting this error when I try to deploy:
Unable to assign value 'data/default/test' to attribute 'url':
Value 'data/default/test' for url does not match expression '^(?:^/.*$)$'
This is the handlers portion of my app.yaml file:
handlers:
# Warning! Static mapping - below - isn't compatible with
# the parametric router's language logic.
# You cannot use them together.
- url: /(.+?)/static/_(\d+\.\d+\.\d+)\/(.+)
static_files: applications/\1/static/\3
upload: applications/(.+?)/static/(.+)
secure: optional
expiration: "365d"
- url: /(.+?)/static/(.+)
static_files: applications/\1/static/\2
upload: applications/(.+?)/static/(.+)
secure: optional
- url: /favicon.ico
static_files: applications/welcome/static/favicon.ico
upload: applications/welcome/static/favicon.ico
- url: /robots.txt
static_files: applications/welcome/static/robots.txt
upload: applications/welcome/static/robots.txt
- url: .*
script: gaehandler.wsgiapp # WSGI (Python 2.7 only)
secure: optional
I'm pretty lost here, as I'm not too familiar with google app engine or web2py. Any help would be appreciated
You're missing a slash in your cron.yaml url specification:
cron:
- description: test
url: /data/default/test
schedule: every 2 minutes synchronized
Is it necessary to handle favicon.ico separately like Google Developers Cloud Playground:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
If so, why not:
- url: /favicon.ico
static_files: favicon.ico
upload: favicon.ico
In my real app.yaml I didn't handle favicon.ico separately and it seems to be working:
application: myAppName
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: website/index.html
upload: website/index.html
- url: /
static_dir: website
Inside the website folder I have the following:
images_folder
favicon.ico
index.html
This isn't about your whole question, just a specific part (when you ask why not remove the backslashes in your favicon.ico). The url configuration is actually a regex (see here). The reason you have backslashes is that a "." in regex means any character. The reason this still works is that a literal "." will match something that matches any character. The backslash "escapes" the "." (turns it into a literal "." rather than any character). You will find that without the "\" it would match, for example, "faviconaico". While this would very rarely be an actual problem, it is good practice to escape any literal characters.
Looks like you're trying to serve a static site. I would use:
application: myAppName
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /images
static_dir: website/images_folder/
- url: /.+ # this should handle the favicon.ico, but see below
static_dir: website/
- url: /
static_files: website/index.html
upload: website/index.html
Although, I'd prefer to explicitly state the favicon handler:
- url: /favicon.ico
static_files: favicon.ico
upload: favicon.ico
And, really, I would put the favicon in the images_folder, for a tidier dev environment, but that's a separate discussion.
It is not necessary to handle requests for favicon.ico separately with their own handler in the app.yaml. This is merely a convention since favicons are the most commonly requested icons and generally requested by default on modern browsers.
A generic handler for all .ico files could be used instead but given the somewhat exceptional nature of favicon.ico with default requests from browsers, it's quite common to use a unique handler.
I have an app.yaml file which looks like this:
application: segmentize
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /css
static_dir: css
- url: /img(.*\.(gif|png|jpg))
static_files: img/\1
upload: img(.*\.(gif|png|jpg))
- url: /
script: index.app
skip_files:
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?index\.yaml
- ^(.*/)?index\.yml
- ^(.*/)?#.*#
- ^(.*/)?.*~
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*/RCS/.*
- ^(.*/)?\..*
- ^(.*/)?dev
- ^(.*/)?old_ver
- ^(.*/)?resources
The images all display fine locally. However, once deployed, they show as broken.
Images in the html are set as follows:
<img src="/img/welcomeimg.png">
Are the images just not uploading when I deploy? What's causing this? The css folder seems to deploy with no issue.
Add the slash in the end of the img in the url and in the upload section:
- url: /img/(.*\.(gif|png|jpg))
static_files: img/\1
upload: img/(.*\.(gif|png|jpg))
I am using google app engine to host my website. I tried to upload sitemap.xml, but when I open the link i.e., www.example.com/sitemap.xml it shows Oops! This link appears to be broken.. I don't know the reason for this. Can anyone tell me what I am doing wrong?
Here is the content of my app.yaml file
application: mywebsite
version: 1
runtime: python
api_version: 1
handlers:
- url: /(.*\.(gif|png|jpg|ico|js|css))
static_files: \1
upload: (.*\.(gif|png|jpg|ico|js|css))
- url: .*
script: main.py
- url: /icon\.ico
static_files: icon.ico
upload: icon.ico
- url: /sitemap.xml
static_files: static/sitemap.xml
upload: static/sitemap.xml
- url: /static
static_dir: static
From here, "Patterns are evaluated in the order they appear in the app.yaml, from top to bottom. The first mapping whose pattern matches the URL is the one used to handle the request.".
You should try moving the catch all handler (url: .*) to the end of the file.