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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:17:14+00:00 2026-06-09T16:17:14+00:00

I am trying to make a custom management command as show in the docs

  • 0

I am trying to make a custom management command as show in the docs here: https://docs.djangoproject.com/en/dev/howto/custom-management-commands/

When I try to run the command from my project directory I am experiencing the following error:

AttributeError: 'module' object has no attribute 'Command'

Here is the file:

#event_expiration.py
from django.core.management.base import BaseCommand, CommandError
from app.models import Event
import datetime

class Command(BaseCommand):
    help = 'deletes expired events'

    def handle(self, *args, **options):

        today = datetime.datetime.now()
        events = Event.objects.filter(date=datetime.date(2011,11,11))

        for e in events:
            e.delete()

        self.stdout.write('Expired events successfully deleted.')

The command I am running is :

$ python manage.py event_expiration

I’ve made sure I am adding the event_expiration.py file within management and commands folders and that those folders have init files. those are in one of my app folders.

Am I overlooking something here? Any help is appreciated, thanks!

EDIT:

Fellow SO user Yuji helped me attempt to debug this a bit but we are still stumped. heres what we did:

First, the full traceback and command:

(venv)matt@inspirion14z:~/Dropbox/PROD/ersvp.it$ python manage.py event_expiration
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/matt/Dropbox/PROD/ersvp.it/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/home/matt/Dropbox/PROD/ersvp.it/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/matt/Dropbox/PROD/ersvp.it/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/matt/Dropbox/PROD/ersvp.it/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 70, in load_command_class
    return module.Command()
AttributeError: 'module' object has no attribute 'Command'

To see what was going on at django/core/management/init.py”, line 70 I placed import pdb; pdb.set_trace() within the file.

While in debug mode we tried:

module.__file__ 

to check if the module was where expected, and it indeed was, with an output of:

'/home/matt/Dropbox/PROD/ersvp.it/app/management/commands/event_expiration.pyc'

Next, we tried manually importing Command in the shell:

>>> from app.management.commands.event_expiration import Command 
Traceback (most recent call last):   File "<console>", line 1, in <module> ImportError: cannot import name Command

Still scratching my head!

  • 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-06-09T16:17:16+00:00Added an answer on June 9, 2026 at 4:17 pm

    What is your file structure like? It should be like so:

    app/
        __init__.py
        management/
            __init__.py
            commands/
                __init__.py
                event_expiration.py
    

    If the structure is as above, try the following:

    python manage.py shell
    >>> from app.management.commands import event_expiration
    >>> dir(event_expiration)
    ['Account', 'BaseCommand', 'Callback', 'Command', 'CommandError', 'Comment', 'Status', 'User', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'clean_phone_number', 'csv', 'models', 'os', 're']
    

    I’ve listed the pure output of running dir on a management command of my own. Give that a try, and report back what is available to the module. You might find yourself getting an error at this point, which may help diagnose. I’m suspecting a problem with importing django itself. I’m guessing the python manage.py shell will fail, which will mean it’s not a problem with your command, but a problem with the project.

    Edit 2:

    The fact that check_expiration was visible in your dir output supports my theory that the folder structure is amiss in someway. Unless there’s specifically a function named that within your module.

    Please do the following and show the output:

    cd /path/to/app/
    find .
    

    Also, show the entire contents of your event_expiration.py file, and the contents of your management/commands/__init__.py file. Be wary of spaces mixed with tabs as whitespace also.

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

Sidebar

Related Questions

I'm trying to make a custom type an instance of Show. Here's theType, it's
I'm trying to make a custom dialog to show a view in this dialog.
I am trying to make a custom command to run on my celery crontabs,
I'm trying to make custom Notifications in Android, following that link : http://developer.android.com/guide/topics/ui/notifiers/notifications.html This
I have been trying to make custom radio buttons using HTML, CSS, and JavaScript.
I am trying to make Custom RelativeLayout which can scale and scroll. Right now
Trying to make a custom :confirm message for a rails form that returns data
I´m trying to make a custom component to javafx, so I make my class
Im trying to make my custom TTreeNode Class for example TCustomTreeNode = class(TTreeNode) private
I'm trying to make a custom tabgroup in appcelerator in which one (or two)

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.