Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7570455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:25:53+00:00 2026-05-30T15:25:53+00:00

I am serving a test file through apache using Bottle. Following are my apache

  • 0

I am serving a test file through apache using Bottle.

Following are my apache config:

WSGIDaemonProcess temp user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias /temp /opt/gridops/usage/temp/adapter.wsgi

<Directory /opt/gridops/usage/temp>
        WSGIProcessGroup temp
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
</Directory>

adapter.wsgi:

import os,sys
os.chdir(os.path.dirname(__file__))
sys.path = ['/opt/gridops/usage/temp'] + sys.path
os.chdir(os.path.dirname(__file__))
sys.stdout = sys.stderr
import bottle
print "++"*10
import index # This loads your application
application = bottle.default_app()

index.py:

from bottle import mount, run 
from routes import app
from bottle import default_app
default_app.push(app)
#run()
#run(app=app, host='192.168.1.3', port=8085) 

routes.py:

from bottle import Bottle , run,route,static_file,view,template,post,request

app = Bottle()
print str(dir(app))
@app.route('/static/<filename>')
def server_static(filename):
    return static_file(filename, root='static')

@app.route('/') 
def index(): 
        return template('template',text='This is index page!')

template.tpl:

<html>
<head>

<link rel="stylesheet" type="text/css" href="static/prettify.css" />
</head>
<body>
{{text}}
</body>

</html>

Directory Listing

temp/
  adapter.wsgi
  index.py
  routes.py
  static/
     prettify.css
  views/
     template.tpl

My issue is whenever I try to access the Bottle app using http://192.168.1.3/temp the webpage shows up without the static files, but whenever i access http://192.168.1.3/temp/ [Please note the extra /] the page loads properly. What modification should I do such that the result of both
http://192.168.1.3/temp and http://192.168.1.3/temp/ become the same?

Any help would be highly helpful

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:25:54+00:00Added an answer on May 30, 2026 at 3:25 pm

    The Problem

    The problematic line is this one:

    <link rel="stylesheet" type="text/css" href="static/prettify.css" />
    

    The address of the CSS file is a relative one, thus the full absolute address is computed from the loaded page location.

    For http://192.168.1.3/temp/, it will be http://192.168.1.3/temp/static/prettify.css (correct).

    For http://192.168.1.3/temp, it will be http://192.168.1.3/static/prettify.css. temp is considered to be a file in the root directory, not a subdirectory of its own right.

    The Solution

    There is no viable way to use a single relative address for referring to the static resources. Your application will likely to have “nested” paths like /article/some-name, or /view/content/566, or something like this, as well as paths as simple as /.

    You can try to specify a root-based path, like /temp/static/prettify.css, in your template, but this means you will have to change the template if you relocate the app itself (say, to myapp.example.com/ from example.com/myapp/).

    Instead, you need to tell the framework to make the correct path to the resource you need to use. Bottle has a function named get_url to facilitate this. Unfortunately, it’s not mentioned in the Bottle tutorials.

    The Code

    Here’s what you should do.

    In template.tpl, call get_url referring to the static handler:

    <link rel="stylesheet" type="text/css" 
          href="{{ get_url('static', filename='prettify.css') }}" />
    

    In routes.py, import get_url:

    from bottle import Bottle, run, route, static_file, view, template, 
                       post, request, get_url
    

    Then, name your handler so you can pass its name to get_url:

    @app.route('/static/<filename>', name='static')
    def server_static(filename):
        return static_file(filename, root='static')
    

    Finally, supply the actual get_url as the template argument when rendering the template:

    @app.route('/') 
    def index(): 
        return template('template', text='This is index page!', get_url=get_url)
    

    Alternatively, instead of supplying get_url in every handler, set up a template default in index.py:

    from Bottle import SimpleTemplate
    SimpleTemplate.defaults["get_url"] = app.get_url
    

    Caveat: The last method seems to be undocumented, but was explained by the Bottle’s author on the mailing list.

    Final Thought

    As every page on a website should have a canonical address, you might want to choose one form (either with a trailing slash or without one) as canonical, and add some kind of redirect from the other one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to speed test jetty (to compare it with using apache) for serving
I am serving all content through apache with Content-Encoding: zip but that compresses on
In Apache Im enabling output compression by adding the following to my .htaccess file:
I'm serving sensitive information in downloadable PDF's and Spreadsheets within a user registration section
I'm serving Django with mod_wsgi and Apache ... unfortunately requests are returning 502 Bad
When using get_serving_url(user.photoBlobKey) to return an image URL from the GAE Blobstore, the Google
I'm serving images two different ways: Using a PHP script for profile pictures for
I'm serving my JSONP JavaScript file on a static file server - GitHub Pages.
I'm loading an external .php file using: <script type=text/javascript src=myfile.js.php></script> Within the external myfile.js.php
I'm serving a Django app behind IIS6 web server. The test server runs perfectly,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.