watsonpy / watson-framework

A Python 3 web app framework.
BSD 3-Clause "New" or "Revised" License
104 stars 12 forks source link

"GET /*/css/*.css HTTP/1.1" 404 #19

Closed mrwert closed 9 years ago

mrwert commented 9 years ago

Hello! I have a problem:

---------------[ /config/routes.py ]--------------- routes = { 'example': { 'path': '/example/:id', 'options': {'controller': 'index.controllers.example'} } 'example2': { 'path': '/example2', 'options': {'controller': 'index.controllers.example2'} } }

---------------[ http://..../example2 ]--------------- "GET /example2 HTTP/1.1" 200 "GET /img/map.png HTTP/1.1" 200 "GET /css/base.css HTTP/1.1" 200

---------------[ http://..../example/blabla ]--------------- "GET /example/blabla HTTP/1.1" 200 but: "GET /example/img/map.png HTTP/1.1" 404 "GET /example/css/base.css HTTP/1.1" 404

How can i to get static files from public/* ? Thanks.

simoncoulton commented 9 years ago

Hey @mrwert, is this locally or via a webserver such as Nginx or Apache? If you can let me know I'll be able to give you some more specifics on how to resolve this issue.

mrwert commented 9 years ago

Is this locally...

simoncoulton commented 9 years ago

If you're launching it from console.py (using ./console.py dev runserver) then make sure that your console.py contains the following:

SCRIPT_DIR, SCRIPT_FILE = os.path.split(os.path.abspath(__file__))
os.environ.update({
    'APP_MODULE': 'YOUR_MODULE',
    'APP_DIR': os.path.join(SCRIPT_DIR, 'YOUR_MODULE'),
    'PUBLIC_DIR': os.path.join(SCRIPT_DIR, 'public'),
    'SCRIPT_DIR': SCRIPT_DIR
})

It will then attempt to server any static files in /public first prior to running any Python code (as PUBLIC_DIR is set to reference 'public'). The general structure I stick to is this:

app/
    .. backend source here
public/
    css/
    img/
    js/
mrwert commented 9 years ago

:+1:

dalirnet commented 7 years ago

hi, i have a problem in load public file return 404 error after run server from console.py