I have one dispatch.yaml that splits 2 services; admin_main.py that controls the admin login, and main.py that controls the user landing. My problem is that admin_main.py does not see its own CSS that I directed it to it. However, it keeps matching with the main.py CSS.
my files are structured as
admin
|assets
|CSS
+styles.min.css
www
|assets
|CSS
+styles.min.css
dispatch.yaml:
dispatch:
# Default service serves simple hostname request.
- url: "example.net/"
service: default
# Default service serves simple hostname request.
- url: "app-example.appspot.com/"
service: default
# Default service serves simple hostname request.
- url: "admin.example.net/"
service: admin
- url: "admin-dot-app-example.appspot.com/"
service: admin
admin_main.py:
service: admin
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /assets/css/styles.min.css
static_files: admin/assets/css/styles.min.css
upload: admin/assets/css/styles.min.css
- url: /.*
script: subdomain.app
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
main.py:
service: default
runtime: python27
api_version: 1
threadsafe: yes
default_expiration: "4d 5h"
handlers:
- url: /assets/css
static_dir: www/assets/css
- url: /assets/img
static_dir: www/assets/img
- url: /.*
script: main.app
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
in the .html the links to the CSS are
<link rel="stylesheet" href="assets/css/styles.min.css">
for both landing sites. But that shouldn't be a problem since the dispatch.yaml separate the incoming calls, right?
I'm not really sure what is causing the problem. Also, I'm new to yaml and I been reading it's documentation.
One solution for this is to store every CSS in the same file, and give them different names. Then in app.yaml in the handlers section add this:
- url: "/assets/css/(.*\\.(css))$"
static_files: {CSS_DIR_IN_PROJECT}/\1
upload: {CSS_DIR_IN_PROJECT}/.*\.(css)$
application_readable: true
that was my only way of solving the problem
Related
We are trying to access .json file inside our python code in Google App Engine.
Here is our app.yaml
service: worker
instance_class: F2
runtime: python27
api_version: 1
threadsafe: true
automatic_scaling:
max_instances: 100
min_pending_latency: 200ms # default value
max_pending_latency: automatic
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /images
static_dir: images
- url: /javascripts
static_dir: javascripts
- url: /(.*\.(gif|png|jpg|json))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|json)$
application_readable: true
- url: /static
static_dir: static
application_readable: true
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /.*
script: worker.app
login: admin
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
We are using it in our application like this.
path = os.path.join(os.path.dirname(__file__)[0], '/static/google_web_app_script_credentials.json')
flow = InstalledAppFlow.from_client_secrets_file(path,self.GOOGLESHEETS_SCOPES )
But we are receiving the error.
IOError(2, 'No such file or directory')
We have tried various options of changing path including path = os.path.join(os.path.dirname(file)[0], '../static/google_web_app_script_credentials.json')
When we go to the GCP console -> Debug and review the current code we are able to see the .json file under static folder. This means that the file is there, we are not able to get the application to read it. This service is as "worker".
From your App Engine app, you don't have access to your static files. Move the file to another location within your project, and you will then be able to access it.
Even more importantly, you don't want to store credentials in your static folder! Anyone on the web will be able to access them via the URL!
My site has 8 pages and it is written in php: https://intercultural.appspot.com After deploying in GAE, it can load and dislpay the index.php page. However, does not display the other pages when I click on other links: Error: No Found The requested URL /file.php was not found on this server.
Here is the directory of my file: hightlighted in blue are the pages of my site.
enter image description here
Here is my app.yaml file:
runtime: php72 </b>
handlers:
# Serve a directory as a static resource.
- url: /styles
static_dir: styles
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
# Serve your app through a front controller at index.php or public/index.php.
- url: /(.+\.php)$
static_files: static/\1
upload: /(.+\.php)$
# I add the "/" to url bellow as suggested but still get same error
- url: /.*
script: auto
secure: always
Although it displays the site address in the browser, it says: Error: No Found The requested URL /file.php was not found on this server.
What is missing in the app.yaml file to route properly to the other pages of my site?
The URL for your final entry in the app.yaml should be url: /.* (with slash). This is necessary to match URLs of https://intercultural.appspot.com/*. You can see an example in the app.yaml reference.
I already fixed it.
The main problem was in the php version. I thought my code was written in php7.2 but actually it was php5.5, hence, the app.yaml didn't work properly.
Here is the app.yaml file:
This is my app.yaml file
runtime: php55
api_version: 1
handlers:
- url: /styles
static_dir: styles
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
application_readable: true
- url: /
script: index.php
secure: always
- url: /(.+\.php)$
script: \1
secure: always
I'd like the app engine to associate index.html with the root URL and main.app with /stats. Here's my app.yaml:
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /
static_files: index.html
upload: index.html
- url: /stats.*
script: main.app
- url: /(.*)
static_files: \1
upload: (.*)
If the URL is /stats, I'd like to print a short message. Here's the code in main.py:
import logging
from flask import Flask
app = Flask(__name__)
#app.route('/stats')
def stats():
return 'Hello World!'
When I try to access /stats, the GCP log says ImportError: No module named main. How can I fix this?
Looks like you entered in a conflict between the /stats handler and the /(.*) handler. As per the documentation for static_files:
If a static file path matches a path to a script used in a dynamic handler, the script will not be available to the dynamic handler.
So, either remove the /(.*) handler, or, as you intent to serve static files with it, I recommend using a handler like the one described in the documentation:
- url: /(.*\.(gif|png|jpg|whateverextension))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|whateverextension)$
Also, don't forget to add the Flask library to your app.yaml file:
libraries:
- name: flask
version: 0.12
Really simple setup; I just want to access any php file from the api folder (technically would like to specifiy /api/.* or something along that lines to include any subfolders) but this setup only returns 404; I have a feeling it is completely ignoring this line - url: /api/app/(.+\.php)$ because if I type asdfasdf.appspot.com/api/app/main.php (there is a main.php in the root directory) it loads. So this tells me it is staying in the root path the whole time. Any suggestions?
application: fsfhakjsldhf9
version: 1
runtime: php55
api_version: 1
threadsafe: yes
env_variables:
MYSQL_DSN: mysql:unix_socket=/cloudsql/fudfsy9:us-central1:fuasdfe-prod1;dbname=f25dsfss9
MYSQL_USERNAME: fddadfs
MYSQL_PASSWORD: 'asfdasdff'
MYSQL_DATABASE: 'asdfasdf'
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /files
static_dir: files
- url: /api/app/(.+\.php)$
script: \1
secure: always
- url: /.*
script: main.php
The - url: /api/app/(.+\.php)$ also needed script: /api/app/\1 to match
When I was trying to run one of the application on google app engine I keep on getting a yell icon the means error. How can I fix it ,so I can run my application.
The error is one the left end side of hello-udacity
Here is the link of the picture of the error: https://plus.google.com/u/1/115545843446144625696/posts/aoRyoN2r2Sd?pid=6168940381509733874&oid=115545843446144625696
In main.py
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello udacity!')
app = webapp2.WSGIApplication([('/', MainHandler)],
debug=True)
In app.yaml
application: hello-udacity
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
The app.yaml file uses the YAML syntax and so your app.yaml should comply with those. The following is a clearer configuration
application: hello-udacity
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
For more on this see about app.yaml in the developer docs