dfunckt / django-rules

Awesome Django authorization, without the database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

autodiscovery

highpost opened this issue · comments

I thought I understood autodiscovery (see #35), but I don't. So I've built a very simple Django project with a set of permissions stored in perms.py and loaded and used in views.py. The relevant line is probably

module = import_module('myapp.perms')

in myapp/views.py. This project app completely works: I can run it with app-setup.sh and (importantly) I can run the related tests with pytest. But if I try to move this app to another environment, say something built with Cookiecutter Django, then I have problems. Modifying import_module() to give it a relative path (.perms) also fails. In addition, note that my permissions file is named perms.py. If I rename it to rules.py and change the above line, it fails.

So can you show me an explicit way of loading a permissions file?

Thanks.

Is there a reason you're using import_module instead of just a standard import? Why not do:

from . import perms

😳 I can't think of a good reason. Thanks. I had tried many variations.