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.
Related
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.
I am trying to utilize the package for editing html content in place and saving it into my database.
https://pypi.python.org/pypi/django-inplaceedit
I've never used Django before until this past week and am wondering how I can install this to be able to use it in my project. I've only been used to using pip install commands and can't seem to use that for this. Thanks.
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/
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
I know this is perfectly possible and a lot of people already doing it, but my problem is slightly different and I couldn't figure out the solution yet:
Let a 3rd party Django App's structure as below:
django-module
module
init.py
views.py
models.py
requirements.txt
setup.py
I want to bundle only the module directory as a submodule, because then I can access views.py file just by typing "module.views". If I import the django-module directory, I would have to write django-module.module.views to access the module files, which is not feasible.
My purpose is to modify the module and make pull requests occasionally to the original repository. Is there workflow that I can follow, or what are the best practices for this purpose?
Pip tips
Pip has support for editable packages and retrieving packages with git, so you could create a virtualenv, use pip to install the packages, and update them using pip when you want.
So you could add:
-e git://git.myproject.org/MyProject.git#da39a3ee5e6b4b0d3255bfef95601890afd80709#egg=MyProject
To your requirements.txt to retrieve that exact commit.
Suggested workflow
I think that the best way to solve your issue is the following:
Make a private fork of the package
Edit the package in a specific development branch in the forked repository
Use the package from your fork's development branch in your requirements file.
When you feel like it, update the forked package where you're using it using pip.
When you're ready to make a pull request, pull origin, rebase your working branch to origin/master, and make the pull request from the master branch of your fork.
This means you have three places where the code is present:
The original repo (where you don't have access)
Your forked repo (where you work on your fork)
Wherever pip installed it (where you use your fork)
The best practice is to keep the submodules exactly as they are.
Once you've added a 3rd party module to your app as a submodule, the next step is to make sure you add that "django-module" directory to your python path. As long as django-module is on your python path, you will be able to use the submodule as you usually would by typing "module.views" as you wish.