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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:01:53+00:00 2026-05-13T23:01:53+00:00

I am attaching a method to the post_save signal of my Django model. This

  • 0

I am attaching a method to the post_save signal of my Django model. This way I can clear some cached items whenever the model is modified.

The problem I am having is that the signal is being triggered twice when the model is saved. It doesn’t necessarily hurt anything (the code will just gracefully error out) but it can’t be right.

A quick example, just printing the model to the console (using the dev server):

from blog.models import Post
from django.db.models import signals

def purge_cache(sender, **kwargs):
    print 'Purging %s' % sender

signals.post_save.connect(purge_cache, sender=Post)

This is using the stable 1.1.1 release of Django.

Updated Information:

With feedback from everyone’s comments, I have modified my question because the issue is now discovering why the post_save is being triggered twice. My guess at the moment is that my models.py code is imported twice and that the post_save is getting connected multiple times.

What would be the best way to figure out why it is being imported/ran twice?

  • 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-13T23:01:54+00:00Added an answer on May 13, 2026 at 11:01 pm

    Apparently, Python is sensitive to the way you import modules. In my case, it wasn’t an issue with any of import code inside my blog application but an issue with the INSTALLED_APPS configuration, which I assume is used by Django to do an initial import.

    Inside my blog application I was using imports such as:

    from blog.models import *
    

    My settings.py was configured as:

    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        ...snip...
        'sorl.thumbnail',
        'mysite.blog',
    )
    

    The “mysite” prefix was added because I originally had import path issues when deploying the site. Later I fixed this issue (so it acted the same as the development server) by adding multiple paths in my WSGI script.

    Removing the “mysite” prefix from the settings.py fixed the issue:

    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        ...snip...
        'sorl.thumbnail',
        'blog',
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a cross browser method of attaching some content in a <div> to
On Drupal 6 I am attaching a file to a node. This can be
this is a normal HTML method of attaching a file. form enctype= <"multipart/form-data" action="savefile.php"
I have some html like this <form id=reportform method='post'> <input type='hidden' id='qid' name='qid' value=<?php
What is the correct (and efficient) way of attaching the contents of C buffer
I perform some decoding process in the native code and call a Java method
I'm working on a reusable database repository method for attaching and saving entities to
What's the ideal way of attaching an external style sheet [or a relatively long
This is my first post and will appreciate if I can get the solution
Is attaching an event listener with jQuery's on() method cross browser compatible? I think

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.