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 3451430
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:08:38+00:00 2026-05-18T09:08:38+00:00

For a super-basic http twisted front-end. How can I make sure no html is

  • 0

For a super-basic http twisted front-end.
How can I make sure no html is ever written back unless I tell it to.

So, I have my /zoo url below.
For any tracebacks, or ‘No Such Resource’ responses, I want to just drop the connection or return an empty response.

I guess it’s a super-simple one but can’t figure it out 🙂
I know I could do it byt not having my specific Child path, but want to do it efficient, would just want to drop it as early as possible.. Maybe not use Resource?

class HttpApi(resource.Resource):
    isLeaf = True
    def render_POST(self, request):
        return "post..."


application = service.Application("serv")

json_api = resource.Resource()
json_api.putChild("zoo", HttpApi())
web_site = server.Site(json_api)
internet.TCPServer(8001, web_site).setServiceParent(application)
  • 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-18T09:08:38+00:00Added an answer on May 18, 2026 at 9:08 am

    Some basics first

    The way twisted.web works is

    There is class called Site which is a HTTP factory.
    This is called for every request. In fact, a function called getResourceFor is called to obtain the appropriate resource that will serve this request.
    This Site class is initialized with root resource. And the function Site.getResourceFor calls resource.getChildForRequest on the root resource

    Call flow is:

    Site.getResourceFor -> resource.getChildForRequest (root resource)

    Now it is time to look at getChildForRequest:

    def getChildForRequest(resource, request):
        """
        Traverse resource tree to find who will handle the request.
        """
        while request.postpath and not resource.isLeaf:
            pathElement = request.postpath.pop(0)
            request.prepath.append(pathElement)
            resource = resource.getChildWithDefault(pathElement, request)
        return resource
    

    What happens is as resources are registered with putChild(path), they become child resources of that resource.
    An example:

    root_resource
    |
    |------------ resource r1 (path = 'help')
    |----resource r2 (path = 'login')  |
    |                                  |----- resource r3 (path = 'registeration')
    |                                  |----- resource r4 (path = 'deregistration')
    

    Some reflections:

    1. Now r1 will server request with path http://../help/
    2. Now r3 will server request with path http://../help/registration/
    3. Now r4 will server request with path http://../help/deregistration/

    But

    1. r3 will server request with path http://../help/registration/xxx/
    2. r3 will server request with path http://../help/registration/yyy/

    For the solution:

    You will need to subclass Site to

    1. check if the path excatly matches the resource returned with pathElement empty and only then process it or
    2. return a resource which will be your handler to handle other aspects

    You will have to create your own resource

    def render(self, request):
        request.setResponseCode(...)
        return ""
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This must be super basic, but I just can't figure it out. I want
pre tags are super-useful for code blocks in HTML and for debugging output while
Ok, this has got to be a super simple problem. I just can't seem
I have a super basic form that shoots out an email. The code is
Sorry, another super basic ASP.NET question. this so embarrassing. I am reading the article
Ok so this is super basic. I just got done implementing the collapsible panel
I'm sure I've got a basic problem in my C knowledge. I have one
i was following the guide http://appfuse.org/display/APF/Using+Struts+2 to make a simple appfuse site, but i
When using Python's super() to do method chaining, you have to explicitly specify your
I'm trying to write a super-simple podcast-to-device downloading service to use for running. I

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.