I have this app engine project structure:
and the this yaml file:
but only chicken.jpg will appear in index.html and not the images inside img/cats or img/puppys.
/img intercepts the others. Put your url handlers in this order:
- url: /img/puppys
static_dir: img/puppys
- url: /img/cats
static_dir: img/cats
- url: /img
static_dir: img
Related
I using Gin framework.
At local development mode: goapp serve
all works fine.
func init() {
route := gin.Default()
route.LoadHTMLGlob("../*/views/**/*.html")
...
}
But after deploy:
panic: html/template: pattern matches no files: ../*/views/**/*.html
OK. I try:
func init() {
route := gin.Default()
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
route.LoadHTMLGlob(dir + "/../*/views/**/*.html")
...
}
Same result.
I try fetch dir:
...
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
...
}
c.String(http.StatusOK, "Dir: ", dir)
c.String(http.StatusOK, "\nOK")
res, err := filepath.Glob(dir + "/*")
c.String(http.StatusOK, fmt.Sprintf("%v | %v\n\n", res, err))
c.String(http.StatusOK, "Dirs:")
res, err = filepath.Glob(dir + "/**/*")
c.String(http.StatusOK, fmt.Sprintf("%v | %v", res, err))
...
Result:
Dir: %!(EXTRA string=/base/data/home/apps/tmp-LEIYJC/_ah)
OK[/base/data/home/apps/tmp-LEIYJC/_ah/exe] |
Dirs:[] |
Ooops. What I done wrong?
UPD:
app.yaml
runtime: go
api_version: go1
handlers:
- url: /images
static_dir: ../static/images
- url: /css
static_dir: ../static/css
- url: /js
static_dir: ../static/js
- url: /fonts
static_dir: ../static/fonts
- url: /.*
script: _go_app
I put app.yaml to subdirectory, cause without that another problem:
[https://groups.google.com/forum/#!topic/google-appengine-go/dNhqV6PBqVc
Folder structure:
app/
app.go
app.yaml
static/
...
frontend/
controllers/
UserController.go
...
models/
UserModel.go
...
views/
home/
*.html
user/
*.html
anotherfolder/
*.html
backend/
controllers/
MainController.go
...
models/
SomeModel.go
...
views/
main/
*.html
anotherfolder/
*.html
...
I found next solution.
I reorginize structure:
app/
static/
...
frontend/
views/
home/
*.html
user/
*.html
anotherfolder/
*.html
backend/
views/
main/
*.html
anotherfolder/
*.html
app.go
app.yaml
frontend/
controllers/
UserController.go
...
models/
UserModel.go
...
backend/
controllers/
MainController.go
...
models/
SomeModel.go
...
...
Change:
app.yaml
runtime: go
api_version: go1
handlers:
- url: /images
static_dir: static/images
- url: /css
static_dir: static/css
- url: /js
static_dir: static/js
- url: /fonts
static_dir: static/fonts
- url: /.*
script: _go_app
It's really strange ecision GAE. I can't put app.yaml to root directory for application because I got panic message for duplication import. And I can't put templates to root directory because that not under scope, only at directory parent to app.yaml
If I'm not mistaken all of your directories should live within the root directory where your app.yaml exists. So you would want something like this. Also, when you want your application to access a static file directory you need to add application_readable: true to that directories definition. See the next example down. Hope this helps.
app/
app.go
app.yaml
static/
...
frontend/views/
home/
*.html
anotherfolder/
*.html
Example Directory Definition:
- url: /s
static_dir: s/
application_readable: true
I am using lamp deployment, using Cloud sql. After uploading my project to xxx.appspot.com. All the css and js files are not opening. It throws:
Error: Not Found The requested URL /public/js/admin/custom.js was not
found on this server.
I am adding the css file as below:
<link rel="stylesheet" href="http://syncspot-ds.appspot.com/public/css/admin/login.css">
<link rel="stylesheet" href="http://syncspot-ds.appspot.com/public/css/admin/bootstrap.css">
<link rel="stylesheet" href="http://syncspot-ds.appspot.com/public/css/admin/font-awesome.css">
My app.yaml file is as below:
application: xxx
version: 1
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: /public/css/admin
static_dir: /public/css/admin
- url: /public/css/front
static_dir: /public/css/front
- url: /public/css/front/images
static_dir: /public/css/front/images
- url: /public/fonts
static_dir: /public/fonts
- url: /public/images
static_dir: /public/images
- url: /public/images/00-ICON LOGO
static_dir: /public/images/00-ICON LOGO
- url: /public/images/admin
static_dir: /public/images/admin
- url: /public/images/background
static_dir: /public/images/background
- url: /public/images/icons
static_dir: /public/images/icons
- url: /public/images/logo
static_dir: /public/images/logo
- url: /public/js/admin
static_dir: /public/js/admin
- url: /public/js/front
static_dir: /public/js/front
- url: /public/js/gmap
static_dir: /public/js/gmap
- url: /public/swf
static_dir: /public/swf
- url: /public/uploads/channel_content
static_dir: /public/uploads/channel_content
- url: /public/uploads/profile_img
static_dir: /public/uploads/profile_img
- url: /.*
script: index.php
My .htaccess file is as below:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|public|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
I am using Code Igniter, AngularJS and MySql. If I use an external css say:
<link rel="stylesheet" href="http://1223.123.123.123/xxx/public/css/admin/login.css">
It is working properly.
Please help me so that I can make a link to css or js file.
For the static directories, the documentation does not have the leading "/" in the static_dir section.
Try to use this format:
- url: /public/css/admin
static_dir: public/css/admin
Long time listener, first time caller.
I'm having some frustrating, seemingly inexplicable issues with Google App Engine, Jinja2, and CSS.
My templates are working, the functionality of my app works (users, blog posts, etc.), but the CSS file shows a big, fat 404 in my Chrome debugging tools and in my Google App Engine logs. Why isn't my /stylesheets/main.css loading?
Dear internet, I'd love to hear that this is just a typo. I'm sure that I'm just an idiot.
Here's my file directory:
stylesheets
main.css
templates
base.html
blog.html
front.html
login.html
newpost.html
signup.html
welcome.html
app.yaml
blogs.py
favicon.ico
index.yaml
main.py
users.py
utilities.py
Here's my YAML file:
application: hello-udacity-5681
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /.*
script: main.app
- url: /stylesheets
static_dir: stylesheets
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
Here's my main.py:
import webapp2
import os
import jinja2
from google.appengine.ext import db
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True)
class Handler(webapp2.RequestHandler):
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def render_str(self, template, **params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self, template, **kw):
self.write(self.render_str(template, **kw))
class MainHandler(Handler):
def render_front(self):
self.render("base.html")
def get(self):
self.render_front()
Here's my base.html:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css"/>
<title>Blog</title>
</head>
<body>
Blog
</body>
</html>
I ran my main.css through http://jigsaw.w3.org/css-validator/ without any issues, so I won't bore you with that.
Why am I still getting a 404 for my /stylesheets/main.css ?
Your app.yaml handler section should be like this
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /stylesheets
static_dir: stylesheets
- url: /.*
script: main.app
In this case, the /stylesheets pattern will match before the /.* pattern will for the appropriate paths. For more information on URL mapping and other options you can specify in app.yaml, see the app.yaml reference.
i have a big problem with images for my project with python (appspots.com).
How to configure the app.yaml for images?
My Images are in the directory /css/images/xy.png
The log say:
INFO 2012-04-22 17:29:42,601 dev_appserver.py:2884] "GET
/css/images/ui-bg_glass_75_e6e6e6_1x400.png HTTP/1.1" 404 -
My app.yaml (only handlers):
- url: /js
static_dir: js
- url: /css/main.css
static_files: css/main.css
upload: css/main.css
- url: /css/jquery-ui-1.8.19.custom.css
static_files: css/jquery-ui-1.8.19.custom.css
upload: css/jquery-ui-1.8.19.custom.css
- url: .*
script: main.py
- url: /css/images/.*
static_dir: css/images
I hope that you can help me :)
The problem is that you have .* before /css/images./* and that pattern matches everything. Rearrange it like this:
- url: /js
static_dir: js
- url: /css/main.css
static_files: css/main.css
upload: css/main.css
- url: /css/jquery-ui-1.8.19.custom.css
static_files: css/jquery-ui-1.8.19.custom.css
upload: css/jquery-ui-1.8.19.custom.css
- url: /css/images
static_dir: css/images
- url: .*
script: main.py
EDIT:
Try removing the /.* from the end of the pattern, as illustrated above.
I registered a Google App Engine app and I have some files below:
/index.html
/css/index.css
/js/index.js
/feedbacks/index.html
/feedbacks/css/index.css
/feedbacks/js/index.js
How should I write the app.yaml file?
Thank you!
application: appname
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon.ico
static_files: img/favicon.ico
upload: img/favicon.ico
mime_type: image/x-icon
- url: /css #your css folder
static_dir: css
- url: /scripts #your javascript folder
static_dir: scripts
- url: /img #your image folder
static_dir: img
- url: /.*
script: your_script.py
Put your first 3 files into a folder name "static"
handlers:
- url: /feedbacks/
static_dir: feedbacks
- url: /css/
static_dir: static
- url: /js/
static_dir: static
- url: /.*
script: main.py
In your main.py
class IndexHandler(webapp.RequestHandler):
def get(self):
self.redirect('static/index.html')
def main():
application = webapp.WSGIApplication([
('/index.html', IndexHandler),
], debug=True)
run_wsgi_app(application)
It's not good to write in this way,
but this will solve your problem.