0

a.example.com b.example.com I want to put in in flask with the same application folder,diferrent config files. I found the following solution,but how to use them?


Create a context processor that injects 'request.host' into your templates and branch accordingly.

For more control, you could create a Site object, instantiated from the current request, and add properties to that, for example:

class Site(object):
  def __init__(self, request):
    self.host = request.host

  @cached_property
  def google_analytics_id(self, default=''):
    if self.host == 'python.example.com':
      return <something>
    elif self.host == 'apple.example.com':
      return <something else>
    return default

Then use site = Site(request) in your context processor and refer to site. in your templates. Candidates for other properties might be HTML meta description and keywords, the site's title etc. This kind of branching is only possible from parts of the application that have access to the request object, of course.

Paul

1 Answer 1

1

Take a look at flask Document, It's quite easy to implement a domain handling function via Application Factories and Application Dispatching which is clearly explained in 'Patterns for Flask' section:

http://flask.pocoo.org/docs/patterns/appdispatch/

http://flask.pocoo.org/docs/patterns/appfactories/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.