I created an small web application using web.py. When deploying and accessing the application through the web browser I get an error related to the location of javascript files.
I followed the structure recommended in learnpythonthehardway.org, so I have the following:
myapp/
bin/
app.py
python_module/
my_module.py
static/
javascript/
myScript.js
templates/
index.html
Within index.html I have next line:
<script type="text/javascript" src="/static/javascript/myScript.js"></script>
I've uploaded the files to /var/www/html/myapp
In apache I have to following configuration:
WSGIScriptAlias /myapp /var/www/html/myapp/bin/app.py
DocumentRoot /var/www/html
Now, when I access http://example.com/myapp I got a 404 error because the application is looking for the javascript in http://example.com/static/javascript/myScript.js
What is the configuration to look for the javascript files in the right location, other than change the src attribute in the script tag within index.html?
Thanks.
答案 0 :(得分:0)
Change:
<script type="text/javascript" src="/static/javascript/myScript.js"></script>
to:
<script type="text/javascript" src="/myapp/static/javascript/myScript.js"></script>
It just is looking for an absolute url based on the root of the webserver. /static
means in /var/www/html/static
. You can also get rid of the first /
if you want but you would have to be careful if you have any subdirectory handling otherwise it will try to find static
inside that other directory.
答案 1 :(得分:0)
解决方法是在apache配置中添加以下行:
Alias /static /var/www/html/movies/static
正如apache文档所说:
&#34; Alias和ScriptAlias指令用于在URL和文件系统路径之间进行映射&#34;