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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:35:54+00:00 2026-05-16T06:35:54+00:00

I am working on an app which would enable a preview function for a

  • 0

I am working on an app which would enable a preview function for a model. Models marked as preview-able would allow for changes to be made in the Django admin interface and previewed on site using the same view as would an object of that type normally use to render itself, but rendered instead with the new (unsaved) object in it’s place.

This is a pretty easy task to do in a bespoke fashion when you know the views or templates ahead of time. But I want this to be reusable and simple.

What I Was Thinking

My idea would be to apply the resolve() urls function to the existing (saved) object’s get_absolute_url() value to discover the view used dynamically. Then call that view, get the returned HTTPResponse and alter it in some fashion before returning it myself.

The Problem

It seems that by the time the HTTPResponse is returned by the object’s natural view the HTML has already been rendered by the template engine.

So I guess the question is: Is there a way to get at a HTTPResponse before the template is rendered and alter the context variables before that happens.

If not then could the same idea be implemented in another fashion. Would using middleware change anything (your still working with a HTTPResponse object there as well).

Thanks,

Marcus

P.S. If you come up with a radically different methodology to solve this problem, I will be sure to attribute that concept to you in the app documentation (despite it being a small app right now).

  • 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-16T06:35:55+00:00Added an answer on May 16, 2026 at 6:35 am

    It is not trivially possible no, the easiest way would actually be to write your own template context processor that checks for example if something like GET['preview'] is set, then sets dictionary values based on some other GET or POST data. Furthermore when other variables are added it should make sure these don’t overwrite the existing values set by this method (otherwise the view would override it anyway with some other data).

    One remark however: completely unintrusive behaviour will often lead to erroneous behaviour. If the view does not know of this preview functionality and e.g. it expects a valid id or redirects to an error page, your preview won’t work (as you don’t really have a valid id). Choosing for views that know of this preview functionality is indeed some more work but will certainly be correct. You could try to make it more generic by using decorators or callable view classes (which can be derivable from some generic base) instead of view methods.

    A completely different approach that is only slightly ‘view’ intrusive, I assume you do not want to save the model so it doesn’t show up in public listings. An approach could be to add a ‘preview’ field and use managers to restrict lookups, so something like this:

    class NoPreviewManager(models.Manager):
    def get_query_set(self):
    return super(MyModelManager, self).get_query_set().filter(preview=False)

    class MyModel(models.Model):
    … #other fields
    preview = models.BooleanField()

    objects = NoPreviewManager()
    allobjects = models.Manager()
    

    In all normal views you can just use MyModel.objects so previews won’t be listed. In the object-specific view you use MyModel.allobjects to also enable defailed views of previews. This way you don’t have to do weird view hijacking things, but you should take care preview objects get cleaned up if they aren’t promoted to real objects. Note that you can also combine many of this logic into a base class.

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

Sidebar

Related Questions

I'm working on an Android app in which I would like to use multi-touch.
I have made an android app which working fine. I implemented the Login functionality
I'm working at an app which would make a POST ajax request to a
I'm working on an android app which would connect to a web server which
I am working on App which will set an alarm on ios for a
i am working on app which deals with proximity alerts. I can add proximity
I am working on an app which calls a rest web service. Sometimes the
I am working on an app which uses Commonslang.jar libraries. I was trying to
I am working on a app which requires me to store some directions for
I am working on an app which needs a very simple progress view .What

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.