I want to clone (via GIT) an external app into my project directory. Unfortunately there is one folder on top of the project that makes Django not see the cloned folder as an app.
For example see allauth. After cloning the app itself is in allauth/allauth resp. from the project view my_project/allauth/allauth. If just adding allauth to INSTALLED_APPS, the app is not found by the server. I also tried adding allauth.allauth, which also doesn't work.
What is the recommended way to clone an external app into a Django project folder (and manage it as submodule for example)?
you can clone it into a vendor/ directory and then symlink it's app folder into your project, but I'd recommend against that.
A better way would be to use a virtual environment, and install the application as an editable package.
$ pip install -e git+https://github.com.au/person/project#v0.1.1#egg=project
This will clone the repo into the src/ folder in your virualenv and set up the paths correctly such that it can be loaded normally with django.
Related
Does anyone know how to symlink using django? I have added sphinx documentation to my django project but as it is not a django package itself so i cannot link it us using the usual django framework. My Boss told me to copy/symlink it into the static folder in a help directory then it will be available through /static/help/ but i have no idea how to do that and online information is sketchy at best.
Symlinking is a file system feature that allows you to create shortcuts from one path to another. It doesn't have anything specifically to do with django.
Because your webserver is serving the contents of your STATIC_ROOT folder, you can just symlink sphinx build folder to a path in your static folder and your webserver will serve it.
Do do so (assuming you are on ubuntu or similar):
ln -s /path/to/existing/sphink/build/ /path/to/django/static/folder/help/
I am very lost on how to manage my django apps. In most projects i use standerd versions of apps, but now i find myself forking projects and working on them simultaneously. How can i use my forked version in some projects and the std version in others? For example:
I have all my django projects in a directory calld DJANGOPROJECTS with a structure like this:
DJANGO PROJECTS
-PROJECT A
-PROJECT B
-APP A (forked version)
-APP B (forked version)
SITEPACKAGES (on default python path)
-APP A
-APP B
I want to use FORKED APP A (forked version) in PROJECT A & APP A in PROJECT B. PROJECT B takes care of it's self. Now how do i make PROJECT A use FORKED APP A?
If I put APP A (forked version) in a virualenv for each project i would have to update all of them each time there was a change. If i keep it out of the virtualenv, when i make local changes to the forked app (without doing a git push) all the projects that use it will get the changes instantly.
I solve this problem by using symbolic links to apps in my virtual environments whenever I want them to use a shared version.
I just found a much better way. Setting up symbolic links is kind of a pain! It turns virtualenv has a built in method to do this.
Modify the path to the package you want to use for that environment in:
yourEnv/Lib/site-packages/packagename.egg.link file.
If you are using easy-install then modify the package path in:
yourEnv/Lib/site-packages/easy-install.pth
For example:
If you want PROJECT-A to use an app called APP-A located in your github directory. Find the files noted above and modify the path from:
c:\users\someuser\documents\github\PROJECT-A\src\APP-A
to:
c:\users\someuser\documents\github\APP-A
Now PROJECT-A will use the version of APP-A in your working repository rather then the one in your virtualenv. You can now work with the APP-A repository and the changes will automatically be integrated with PROJECT-A without having to push or pull changes.
Which is the best way to have two different repositories on the same Django project?
I started developing a project months ago and I have the whole folder in the repository. I want to reuse some apps in the project and I would like to create a different repository for them since they will be spin-offs project. But I want to keep it updated.
Which is the best workflow, methodology, etc... to achieve this? Or is it a bad approuch?
Thanks!
Xavi
You can wrap each app as a python package, which has its own GIT repo. And save all your packages in some private (or public?) python packages repository (like Gemfury).
Then, in your projects, just use the app as you install django itself.. pip install myapp
This way the apps a reusable and decoupled from any project.
(This works very well for myself.. perhaps there is a better way)
You can use submodule,
$git submodule add git://github.com/yourusername/project2.git project2
$cat .gitmodules
.gitmodules output:
[submodule "project2"]
path = project2
url = git://github.com/yourusername/project2.git
If you want to Clone some git project like submodule,
git clone git://github.com/yourusername/project2.git
cd project2
git submodule init
I have a django project sitting in a bitbucket repository. Is it possible to automate using buildout, the following process:
1. Install django
2. clone the django project from hg repository
3. install the dependency modules of the django project
Update: I have achieved what I wanted to, with the help of mr.developer extension as suggested by Ross.
While doing that I had another question popping up. Which is the best place to specify the dependencies - in the buildout.cfg or in the setup.py of the 'develop' modules? For now I have duplicated the specification.
Generally, you make your checkout the buildout itself, so you'd place buildout.cfg and bootstrap.py in your project root. That way when someone checks out/clones your project, they just do the bootstrap/buildout dannce and they're up and running.
If you have multiple checkouts, then look into mr.developer.
I'm still busy with my Django learning adventure. In another post I asked about how to structure a Django project and applications using buildout. In the details of doing this arose another issue, simply installing 3rd party Django applications using either easy_install or setup.py. My question is, where should you install a Django application? If looking at Django documentation, one would think to put a Django application inside the project folder. But if your Django application is an egg (a mystifying term in my opinion) and you use easy_install without option '-b' (build-directory) the application will be installed into your current python site-packages directory. Using option '-b' will put a copy of the application in your directory, but still will install it in your current site-packages directory. Then there are other options like --install-dir and prefix. Also how should installation happen when using setup.py which have similar options as buid-directory, install-dir, and prefix?
Is there a 'good practice' standard for installing 3rd party Django applications into a Django project?
Thank a lot,
Todd
They usually aren't installed directly into the project. They're either installed into the system's site-packages/ directory, or in the virtualenv's site-packages/ directory, or in some other well-defined place that the sysadmin has set for this purpose.
This is where virtualenv comes into its own. It basically enables a project-specific site_packages directory, where you can install all the third-party applications that relate to your project. I'd definitely recommend it.
Follow these steps :
change the path according to your local setup
C:\Python27\Lib\site-packages>python pip install django
Create Project
Go to folder where you want to create a project
E:\djangoProject>C:\Python27\Lib\site-packages\django\bin\django-admin.py startproject myproject
python manage.py help is used to list all the commands
Manage.py This file is kind of your project local django-admin for interacting with your project via command line (start the development server, sync db...)
Run Server
E:\djangoProject\myproject>python manage.py runserver
Create App
E:\djangoProject\myproject>python manage.py startapp myapp
Go to myproject settings.py and register your app “myapp” created under INSTALLED_APPS
Migrate DB E:\djangoProject\myproject>python manage.py migrate
Migrate will create necessary tables or collections depending on your db type, necessary for the admin interface to run