I have create an app in php. The folder "myapp-test-1" has a file called index.php and a folder CSS which includes the file main.css which is the css file for index.php .I am trying to create my app yaml file in order to upload my project in google's app engine. This is my app.yaml file:
application: myapp-test-1
version: 1
runtime: php
api_version: 1
handlers:
- url: /.*
script: index.php
- url: /css
static_dir: css
- url: /css/
script: main.css
when test it in browser it seems that index.php file is not full loaded. Moreover the css for index.php is not working.
You need to have the
- url: /.*
script: index.php
last, because if you have it first, the order in which GAE will read this file is this, then the other two css ones. The regex .* next to url says that all URLs will lead to index.php, so putting this last will allow GAE to read the css ones first. You also don't need to include
- url: /css/
script: main.css
if you're only going to load the css files in your index.php.
So overall, it should look like
application: myapp-test-1
version: 1
runtime: php
api_version: 1
handlers:
- url: /css
static_dir: css
- url: /.*
script: index.php
I believe that you should try to leave only :
- url: /.*
script: path/index.php
and remove the two references to the css.
from inside the index.php, make sure that you call your css file using the right path.
eventually if you use firefox, the function "inspect element" and the console, will tell you why your file is not loaded...
good luck
Related
I am fairly new to Google App Engine. When I keep files in images folder and run bat file, it uploads images properly but when I remove those images and put new images to upload, it removes previous images.
My app.yaml looks like this
application: testcdn
version: 1
runtime: python27
api_version: 1
threadsafe: true
default_expiration: "1d 1h"
handlers:
- url: /css
static_dir: css
- url: /images
static_dir: images
- url: /js
static_dir: js
- url: /.*
static_files: index.html
upload: index.html
Also when 2 developers try to upload images to the same cdn store with different google accounts, it removes images previously uploaded by other developer.
Please suggest.
Your local files mirror your deployed files. If you remove files locally, then deploy, the remote files will be deleted. You are not just defining the files to upload, but the files to mirror remotely.
I am not sure about your 2nd comment. Do the files have the same filenames? You will have to provide the upload code for diagnosis.
I'm using webapp2 and python 2.7 on my app engine application. However, I'm having a problem with the url on app.yaml.
I have my static files inside a static/ directory, in the root of my path. So inside of static/ I have static/scripts/MyScript.js
When I set app.yaml like:
application: myapp
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /.*
script: myapp.app
- url: /static
static_dir: static
libraries:
- name: webapp2
version: latest
In my HTML code, the js is called like:
<script src="static/scripts/Fuel.js"></script>
But, the file is not loaded, and I get a 404 error. (This problem happens also for .css files.)
However if I change the first url in app.yaml to:
handlers:
- url: /
script: myapp.app
The static files are loaded, but when I try calling the routes url in my app, like an url I call in a form to save some data on server, this route is not found and I also get a 404 error.
Here is my routing code in myapp.py file.
app = webapp2.WSGIApplication(
[('/', MainHandler),
('/save', SaveData),],
debug=True)
So if I try to access myapp.appspot.com/save, it returns me a 404 error, saying:
The requested URL /save was not found on this server.
Any ideas? If you need more information about it, just ask on the comments.
Thanks.
Put your catch all url /.* at the bottom since this is evaluated in order. Meaning it never pass after that.
handlers:
- url: /static
static_dir: static
- url: /.*
script: myapp.app
I made a website using Google app engine however, if I want to link from the main page to a different page in the folder structure, is does not load on the website.
The links are fine, they work if I check it on a browser directly from my drive. Do I need to put the entire folder in a seperate folder somewhere for app engine to access it or does it need to be in one single, messy file?
Check the app.yaml file, you have to edit it and add the folders.
Ex:
application: xxxx
version: 1
runtime: python
api_version: 1
handlers:
- url: /stylesheets
static_dir: resources/stylesheets
- url: /imgs
static_dir: resources/imgs
- url: /js
static_dir: resources/js
- url: /html
static_dir: resources/html
mime_type: text/html
- url: /.*
script: main.py
You have to put all your files that you want to display directly through an HTTP call in WEB-INF folder, assuming that you are coding in Java.
When I deploy my app to Google App engine the CSS is no longer found. The app is fine in the localhost. I'm not sure why this is exactly. Does the app engine change the file structure? I get the following error in the log:
2012-10-26 14:04:37.727 Static file referenced by handler not found:
stylesheets/main.css
Here's my app.yaml
application: vipermonkeyswhofly
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /.*
script: vipermonkeyswhofly.app
libraries:
- name: jinja2
version: 2.6
My index.html has this url:
<link rel="stylesheet" type="text/css" href="/stylesheets/main.css" /> </head
I appreciate any help that you can provide. I'm sure it's something obvious that I'm missing but it's eluded me up to this point.
Check that the folder and file are also lower case on your filesystem. (/stylesheets/main.css)
If you're on Windows then it seems not to be case sensitive but the production environment is.
Another thing of note is that the main.css is only created in the section titled "Using Static Files" which comes after "Using JSPs". So, if your like me and deploy after each section, you'll see this error until you create the main.css file.
Also worth noting that in your app.yaml file, if you have the following mappings:
# static directories #
- url: /css
static_dir: css
- url: /img
static_dir: img
- url: /js
static_dir: js
your HTML file needs to reference them like this (note the leading / in the file path):
<link href="/css/style.css" rel="stylesheet"/>
I'm having problems getting my assets folder to upload to the root, but also allowing a custom url handler /cron to upload too.
application: appname
version: 1
runtime: python
api_version: 1
handlers:
- url: /cron
script: assets/backup/main.py
- url: /
static_files: assets/index.html
upload: assets/index.html
- url: /
static_dir: assets
As you can see, my backup script is also located in my assets or static folder. If I remove my static_dir: assets handler, my /cron handler works fine.
I also tried changing the url to /assets to see if I could overwrite it that way.
Any idea why this happens and how I can fix it?
You are defining the whole assets directory as static with static_dir: assets. You can't run any script inside a static_dir. The fix is to move assets/backup/main.py to outside the directory defined as static_dir.