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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:30:03+00:00 2026-06-16T04:30:03+00:00

I’m trying to diagnose the error in my custom middleware somehow brings down my

  • 0

I’m trying to diagnose the error in my custom middleware somehow brings down my session middleware.
The custom middleware is a simple app which deletes old files in some folders.

class DeleteMediaMiddleware(object):
    time_limit = 100.

    def check_folder(self,folder):
    '''Deletes the files older than "time_limit" '''
        os.chdir(folder)
        files_in_folder = os.listdir(os.curdir)
        for my_file in files_in_folder:
            creation_time = os.path.getmtime(my_file)
            file_lifetime = time.time() - creation_time
            if file_lifetime > self.time_limit:
                os.remove(my_file)

    def process_request(self, request):
    '''Standard middleware method which runs on every request'''
        self.check_folder(config.input_folder)
        self.check_folder(config.output_folder)
        self.check_folder(config.plot_folder)
        self.check_folder(config.report_folder)
    return None

It is located in the Django project folder. (The levels is how Django creates by default. In my case the project is named expofit, and the folder structure is expofit/expofit)

project_folder_lvl1/project_folder_lvl2/mymiddleware.py

I added the middleware to Djagno settings:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'server.mymiddleware.DeleteMediaMiddleware',
    )

However, i end up with an error.

Exception Value:    no such table: django_session

which is from checking a session value in views.py:

....    
if request.session.has_key('user_id'):
....

As soon as i disable my middleware in Django settings, everything works normally.

UPDATE:

I sucesfully open the database, which is an sqlite file located in the project_folder_lvl1, and locate the table which isn’t accessible.

Here is the complete Django traceback.

Environment:

Request Method: GET
Request URL: http://localhost:8000/expofit/

Django Version: 1.4.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'expofit_django_app',
'south',
'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'server.mymiddleware.DeleteMediaMiddleware')


Traceback:
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
77.         return view_func(*args, **kwargs)
File "/home/alan/Desktop/expofit/expofit_hg/py/server/expofit_django_app/views.py" in check
59.         return view(request, *args, **kwargs)
File "/home/alan/Desktop/expofit/expofit_hg/py/server/expofit_django_app/views.py" in start
23.     if request.session.has_key('user_id'):
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in has_key
103.         return key in self._session
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session
165.                 self._session_cache = self.load()
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in load
19.                 expire_date__gt=timezone.now()
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/db/models/manager.py" in get
131.         return self.get_query_set().get(*args, **kwargs)
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/db/models/query.py" in get
361.         num = len(clone)
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
85.                 self._result_cache = list(self.iterator())
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator
291.         for row in compiler.results_iter():
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
763.         for rows in self.execute_sql(MULTI):
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
818.         cursor.execute(sql, params)
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/db/backends/util.py" in execute
40.             return self.cursor.execute(sql, params)
File "/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
337.             return Database.Cursor.execute(self, query, params)

Exception Type: DatabaseError at /expofit/
Exception Value: no such table: django_session

Looking for ideas on how to debug this problem?

  • 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-16T04:30:05+00:00Added an answer on June 16, 2026 at 4:30 am

    The problem was fixed by adding the absolute path to the sqlite database.

    settings.py which yielded the error:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'expofit_database',  
            ...
            ...      
    

    new settings.py:

    PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join( PROJECT_PATH, 'expofit_database'),  
            ...
            ...      
    

    From what i figured, the problem was in calling the

    os.chdir(folder)
    

    inside the check_folder function which messed up the runtime paths.
    Although setting the absolute path solved the problem for accessing the database, i removed the os.chdir(folder) to prevent potential errors in the future.

    def check_folder(folder):
        time_limit = 100.
        files_in_folder = os.listdir(folder)
        for file_name in files_in_folder:
            file_path = os.path.join(folder,file_name)
            creation_time = os.path.getmtime(file_path)
            file_lifetime = time.time() - creation_time
            if file_lifetime > time_limit:
                os.remove(file_path)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app for my school newspaper, which is run completely online
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.