B
B
Bojczuk2015-09-10 16:24:40
Django
Bojczuk, 2015-09-10 16:24:40

How to override a module method in Django?

There is a Django application, the package is installed django-photologueand traditionally included in INSTALLED_APPS. There was a need to rewrite one of the methods in this module in the lib/python3.4/site-packages/photologue/views.py. How to do it correctly without affecting the files in site-packages?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2015-09-10
@sim3x

There's not a lot of code, so it's easier to override the behavior right next to your views.

A
Alexey, 2015-09-10
@MAKAPOH

I usually add some directory to sys.path in django settings file:

# settings.py
BASE_DIR = path.abspath(path.join(path.dirname(__file__), '..'))
sys.path.insert(1, path.join(BASE_DIR, 'apps_third_party'))

Then in apps_third_party I copy the code that needs to be changed. In your case, copy the photologue directory and edit it in a new location.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question