[Django]-Customize django runserver output

1đź‘Ť

âś…

i think best way is use logging and add some code to this

like

from django.db import connection
sql=connection.queries

and

doc = {
                'record_hash': hash,
                'level': record.level,
                'channel': record.channel or u'',
                'location': u'%s:%d' % (record.filename, record.lineno),
                "message": record.msg,
                'module': record.module or u'<unknown>',
                'occurrence_count': 0,
                'solved': False,
                'app_id': app_id,
                'sql': sql,
            }

read more about this in http://docs.djangoproject.com/en/dev/topics/logging/

2đź‘Ť

I wouldn’t recommend modifying the runserver command, but…

django-devserver has a replacement for the manage.py runserver command that allows extending the output to show any information you’re interested in.

The instructions on the page linked above show how to install, and near the bottom there is a “Building Modules” that shows an example for extending the output.

I’m not exactly sure what you’re looking to output, but maybe something like:

from devserver.modules import DevServerModule

class ViewNameModule(DevServerModule):
    logger_name = 'view name module'

    def process_view(self, request, view_func, view_args, view_kwargs):
        self.logger.info('View name: %s' % '.'.join([view_func.__module__, view_func.func_name]))
👤meshantz

0đź‘Ť

Not the exactly the answer to your question, but I think django-debug-toolbar shows all the queries and many other useful information.

👤Myth

Leave a comment