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

  • Home
  • SEARCH
  • 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 85293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:04:00+00:00 2026-05-10T22:04:00+00:00

I am writing a web-framework for Python, of which the goal is to be

  • 0

I am writing a web-framework for Python, of which the goal is to be as ‘small’ as possible (currently under 100 lines of code).. You can see the current code on github

Basically it’s written to be as simple to use as possible. An example ‘Hello World’ like site:

from pyerweb import GET, runner  @GET('/') def index():     return '<strong>This</strong> would be the output HTML for the URL / '  @GET('/view/([0-9]+?)$') def view_something(id):     return 'Viewing id %s' % (id) # URL /view/123 would output 'Viewing id 123'  runner(url = '/', # url would be from a web server, in actual use        output_helper = 'html_tidy' # run returned HTML though 'HTML tidy' 

Basically you have a function that returns HTML, and the GET decorator maps this to a URL.

When runner() is called, each decorated function is checked, if the URL regex matches the request URL, the function is run, and the output is sent to the browser.

Now, the problem – outputting headers. Currently for development I’ve just put a line before the runner() call which does print Content-type:text/html\n – this is obviously a bit limiting..

My first ideas was to have the functions return a dict, something like..

@GET('/') def index():     return {         'html': '<html><body>...</body></html>',         'headers': {'Location':'http://google.com'}     } 

I really don’t like this – having to return a dict with a specifically named key isn’t nearly as nice as just returning a string..

I could check if the returned data is a dict, if so use returned_data['html'] as the output, if it’s a string, there is no custom headers to be sent… but this means to go from no headers (which would be the case a huge majority of the time) to headers, you’d have to change the return function from return my_html to return {'html':my_html} which isn’t very elegant either..

After writing this, I discovered ‘Sinatra’ – a similar-in-use Ruby library, and looked at how it dealt with headers:

get '/' do     content_type 'text/css', :charset => 'utf-8' end 

This seems like it could be nice enough in Python:

@GET('/') def index():     header('location', 'http://google.com') 

To implement this, I was considering changing how the functions are executed – instead of simply using the return value, I would change sys.stdout to a StringIO, so you could do..

def index():     print '<html>'     print '<head><title>Something</title></head>'     print '<body>...</body>'     print '</html> 

..without having to worry about concatenating a bunch of strings together. The upshot of this is I could have a separate stream for headers, so the above header() function would write to this.. Something like:

def header(name, value):     pyerweb.header_stream.write('%s: %s' % (name, value)) 

Basically, the question is, how would you output headers from this web-framework (mostly in terms of use, but to a lesser extent implementation)?

  • 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. 2026-05-10T22:04:00+00:00Added an answer on May 10, 2026 at 10:04 pm

    Look at PEP 333 for an excellent design pattern for a very lightweight web server. If your server has this exact API, you can reuse it in a lot of context with a lot of other products.

    PEP 333 (WSGI) suggests that you don’t directly return the page, but you provide the HTML page to a ‘start_response’ callable object, which wraps your HTML in the proper HTTP response, with the proper headers.

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

Sidebar

Ask A Question

Stats

  • Questions 101k
  • Answers 101k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use a dictionary of items mapped to their… May 11, 2026 at 8:00 pm
  • Editorial Team
    Editorial Team added an answer There is no easy fix for this. You now have… May 11, 2026 at 8:00 pm
  • Editorial Team
    Editorial Team added an answer I've done this on a C++ code base that was… May 11, 2026 at 8:00 pm

Related Questions

I am going to spend 30 minutes teaching Perl to an experienced programmer. The
I am building a REST based API (Read only) for accessing services of my
I have been given to the task of writing a coding standards document and
I am writing a setup program for my ASP.NET web site, and I need

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.