For static directories that are not related to my own app, but to other Django modules (at the project_name/static directory ), do they need to be checked in to version control or do they automatically generate if a Django project is checked out somewhere else?
The project-wide django static directory, $STATIC_ROOT, referenced by settings.py, should be not be in source control. Only the static directory for each app should be in source control.
In development, static files can be served by runserver.
In production, the files are collected from each installed app to the single $STATIC_ROOT via
python manage.py collectstatic
See https://docs.djangoproject.com/en/1.7/howto/static-files/.
So you should put the static directory for any app you develop in source control, but you should treat the static directory for any third-party apps the same as any other directory for those apps. I.e., if you install an app using pip, that will include its static directory if any.
Related
I read some similar issue on Stack Overflow but still stuck with this problem. The web Django can deploy on IIS well except CSS style for admin and all CSS.
What I tried:
Use whitenoise -> I got error when I wrote whitenoise tag in middleware. then I stopped use this way
Use add virtual directory
more information -> I created virtual enviroment
venv_>my django>app folder
honestly, I really don't know where virtual directory (named static) should be, then I tried at
default web site
venv_
my project folder (my static folder after use collectstatic Django)
I tried to use path physical to (my static folder after use collectstatic Django)
it still not working
More information:
I used findstatic but got another path not (collectstatic path in my project app)
it is in my venv_ package?
I've developed a stand-alone Django app that has one static JS file. On some installations, Django development server can't find the static file. The app is installed as a Python Package with pip, and I can find the JS file in site-packages/appname/static/js/myfile.js
I've installed the Django Debug Toolbar, and when looking at the "static" panel, I see a list of "static file apps". My app is not listed there. How can I tell Django it should look at my app's static file folder, too?
I'm using Django 1.6.3, with the following static file finders:
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
The django.contrib.staticfiles app is installed.
Update: When using manage.py collectstatic, files from the app are not copied.
OK, this was stupid.
The app in question was previously part of the old project. I've changed it into an independent app on a different development machine. When I wrapped it as an independent app I deleted the myproject/myapp folder on the other machine, and used pip install to install it to the project's virtual env.
Then I used this development machine, did a git pull and pip install. Turns out this *doesn't delete the myproject/myapp folder - it just deletes all the files handled by git. .pyc files are not deleted, so the folder remained, and Django looked for static files in that folder, instead of the one in site-packages.
Removing myproject/myapp fixed this.
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 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.
I need to setup a Django dev environment.
I did a git clone and pulled all the django project files from production on my local machine (a Vagrant enabled VM).
The problem is that my local machine has a different path to the project than my production ( and I can't change that) so it's having problems finding modules stated under INSTALLED_APPS on my local machine.
For example on the production my project is on the /myproject folder while on my local machine is under /vagrant/web/myproject.
On the production I'm accessing my app modules like this:
INSTALLED_APPS = ( 'myproject.myapp')
Also within the Django apps I'm accessing various app modules like this:
from myproject.myapp.models import *
What do I need to do to emulate production paths to my modules on my dev box so I don't have to change the paths to the modules on my local machine?
If you're doing project-relative imports, all you need to do is ensure that the path directly above your project is on the PYTHONPATH.
You need only issue the following at the command line:
export PYTHONPATH='/vagrant/web'
If you're using virtualenv, you can add that line to your environment's bin/activate file.
The path to your application directory should not matter there as long as you dont have hard-coded paths in settings.py, what web server are you using?
In your settings.py:
import os
prj_root = os.path.realpath(os.path.dirname(__file__))
And prj_root will be path to your root project folder