GithubHelp home page GithubHelp logo

Comments (3)

thelittlebug avatar thelittlebug commented on August 16, 2024 1

i've changed the manage.py to get this working.

import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "highlander.settings.dev")
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


def prettier_errors():
    import pretty_errors

    pretty_errors.configure()
    pretty_errors.replace_stderr()


if __name__ == "__main__":
    prettier_errors()
    main()

from prettyerrors.

onelivesleft avatar onelivesleft commented on August 16, 2024

I have no Django experience, you'd be better asking about this on a Django forum.

from prettyerrors.

tankorsmash avatar tankorsmash commented on August 16, 2024

i've changed the manage.py to get this working.

def prettier_errors():
    import pretty_errors

    pretty_errors.configure()
    pretty_errors.replace_stderr()

This gets it printing but the HTTP print lines are joined together. I'm on Windows Powershell.

Instead of messing with manage.py, this middleware gets close for requests but still prints out the error after if you don't return a response from the middleware:

from sys import exc_info
import pretty_errors

class PrettyErrorsMiddleware:
	def __init__(self, get_response):
		self.get_response = get_response
		pretty_errors.configure()

	def __call__(self, request):
		return self.get_response(request)

	def process_exception(self, _, exception):
		_, _, traceback = exc_info()
		pretty_errors.excepthook(exception.__class__, exception, traceback)
                #return http.Response() to stop the error from printing out
# settings.py
MIDDLEWARE += ["my.path.to.PrettyErrorsMiddleware"]

It would be nice to have prettier printing for server startup exceptions, instead of just requests though.

from prettyerrors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.