Search code examples
djangopython-2.7pylint

How to use pylint_django?


I am new to linting, using python 2.7 and pylint-django 0.7.2 for linting my django code.

pylint --load-plugins pylint_django [..other options..] <path_to_your_sources>

I didn't understand the path_to_your_sources in the above command? Do I've to give a .py file or the django directory?

I tried running with a .py file, getting the below error:

ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings

Can anyone please let me know what this error is saying and how to use pylint_django.


Solution

  • Just do this and you're all set.

    Set Env Var:

    DJANGO_SETTINGS_MODULE=your_settings_file_path
    For eg DJANGO_SETTINGS_MODULE=mysettings.setting.base
    

    Then run this command:

    pylint --load-plugins=pylint_django --rcfile your_pylint_filename
    Use * to run pylint for your whole project