Creating an installable Django app with a 3rd party dependency - django

I am in the process of creating an installable Django app on pypi which can be added to INSTALLED_APPS. The app works correctly up to this point.
The problem now is that I wish to use Django Rest Framework within my app. Does this mean that users will have to add my app as well as Django Rest Framework to their INSTALLED_APPS when installing my app?
Is there a way to simply add my app to INSTALLED_APPS without the user being aware of or needing to worry about anything else. They don't need to know that I use Django Rest Framework under the hood?
I have already added djangorestframework to my setup.py so that it is installed when the user pip installs my package. So the questions is around whether or not the user has to explicitly add it to INSTALLED_APPS.

The best you can/(should) do is add rest framework as dependency in your application, and instruct users to add rest framework in installed apps. Because project settings should not be modified pragmatically, should explicitly hard coded and remain read-only within code base.
You should instruct users to add rest framework in installed apps like this package does
One other thing you can do is check whether user have installed 'rest_framework' or not in ready hook of your AppConfig class like this
class YourAppConfig(AppConfig):
name = 'yourapp'
def ready(self):
from django.conf import settings
if 'rest_framework' not in settings.INSTALLED_APPS:
raise ImproperlyConfigured('rest_framework must be in installed apps.')
It will at least force them to do so.

You can add djangorestframework to your install_requires in your setup.py.
Then, when your user runs pip install yourapp, it will install rest framework as well.
Personally, I would say to add 'yourapp' and 'rest_framework' to INSTALLED_APPS in your setup instructions. You may be able to find a way to automatically add it, but it might not be worth the effort. As an example Django Debug Toolbar removed its automatic setup code to reduce complexity.

Related

Django REST framework unrecognized

I already have django rest framework installed in my project, as you see when I run pip freeze:
However, when I try to import any module it does not recognize it, so it is not possible for me to go check the function or class or whatsoever I am importing.
Who knows what the problem is?

Overriding a view.py file in an external Django package

I am working on a Django project and had to install a package with pip: 'authemail'. I want to override the view.py file and the serializers.py in this package. So I can customize the code without touching the package. What is the best way to do this?
My solution for now:
I have copied the whole package in my application as an app. Django always tries this path for its imports. I removed the package from the requirements and make the changes in my newly added app. This is of course the last resort but for me the best route. Because when in the future the package will support my features I can easily switch back to using a package.

Error with django-registration module: AppRegistryNotReady("Models aren't loaded yet.")

I am having a problem getting the Django registration module to work. I am relatively new to Django, having only worked through a few examples, now wanting to rebuild a site using user registration, that I've previously made with python.
I am using Python 2.7, Django 1.7.1, and my operating system is Ubuntu 14.04. I'm also using Eclipse/PyDev for my IDE.
I keep getting the error message:
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
I have installed both the django-registration and django-registration-redux modules, understanding that there may issues with installing django-registration in Django 1.7. Should I copy the registration module directly into my app, although not advised, but for troubleshooting? Should I uninstall something before I install a new package?
The django-registration module resides in "/usr/local/lib/python2.7/dist-packages." I'm not sure where the django-registration-redux module should have ended up at, although it deposited "django_registration_redux-1.1.egg-info" with the dist-packages.
I have added 'registration', to the settings file, and to my urls' file pattern I've added: (r'^accounts/', include('registration.backends.default.urls')),
I've read numerous on-line postings about this issue, but I can't get around this block. Should I uninstall Django 1.7.1, and install Django 1.6 to avoid this impasse?
Thanks,
Walter Goedecke
Have you considered using django-allauth instead of django-registration?
As I understand it, django-registration is no longer being maintained.
Were you able to resolve this?
When you say “I have installed both the django-registration and django-registration-redux modules”, do you mean you are trying to use both at the same time, or you tried one and then the other? You should only be using django-registration-redux, I believe django-registration stopped being maintained during one of the Django 1.6 releases, maybe it was 1.5 don’t recall. If its of any help, we have Django 1.7.9, Django 1.8.1, and Django 1.8.3 working with django-registration-redux 1.1.
It sounds like you are installing your python packages system wide (you said its residing in /usr/local/lib/python2.7/dist-packages). There is a great tool called virtualenv that lets you keep all of your projects isolated, in their own virtual environment with their unique dependences. This way one project can be using django 1.5 while another is using django 1.7, one project can use django-registration-redux while the other uses allauth, etc. The other great thing about it, is that it makes your projects more portable, easier to share, and easier to update.
If you haven’t tried it yet, you should check it out!
http://docs.python-guide.org/en/latest/dev/virtualenvs/
I found this link very helpful when I was first getting started with Python and Django development:
http://www.jeffknupp.com/blog/2013/12/18/starting-a-django-16-project-the-right-way/

django-registration: Where should I put the "registration" directory?

I'm using the django-registration app from https://bitbucket.org/ubernostrum/django-registration/, and I'm a bit confused as to where I should place it.
I've added "registration" under INSTALLED_APPS in settings.py (as instructed), but shouldn't the registration app mentioned be in my project directory, with all my other apps? This seems to make more sense to me than having it somewhere else (ie. PYTHONPATH).
So, I'm thinking of cloning the repo, just grabbing django-registration's registration app, abandoning all the other files included in django-registration (INSTALL, README, docs, etc.), and sticking that registration app in my project directory.
This way, I can edit the models to include more fields, reflect that in the forms, etc.
Is this wrong?
(Sorry, it's my first large Django project)
Normally you wouldn't touch the files of django-registration - if you want to add your own custom fields for a user profile, you'd do something like this:
Saving profile with registration in Django-Registration
When you install a django package, this package are on your PYTHONPATH, so your project see it.
So just install via pip or easy_install (pip is better), and put on settings' INSTALLED_APPS the 'registration' package
Follow this instructions

HowTo Install the Django emailauth App into a New Project

I'm a Django newbie and am interesting in understanding how to install the EmailAuth app into my new project:
http://github.com/redvasily/django-emailauth
Seems like Django apps are meant to be plug in play so I must be missing something....
Here's what I tried.
I created a new project
copied the emailauth directory over
Updated my settings.py with the INSTALLED_APPS 'emailauth' and made sure my settings.py had correct db and email settings.
But that failed, I must be missing some other installation requirements?
Thanks for any help you can provide.
Django apps are Python modules.