Symlink to static html page Django - django

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/

Related

Deploy static file of Django on IIS

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?

Django sphinx docs made by cookicutter folder confusion

I'm a bit confused by the folder structure the sphinx makes for its documentation when starting a fresh new Django project with cookiecutter.
I have my project set up in docker, as per instructions, everything is serving fine and I have the following folder structure for the documentation.
When I run the command make html in the docs container (or by using the docker-compose local.yml file) I get the following structure.
A new folder "html" is created and it's containing everything from the surrounding folders. Is this correct? Am I understanding the process correctly?
For me, it looks like some bad settings for some source folder somewhere.
I'm an experienced python dev, familiar with Docker as well, but I'm pretty new to Django and sphinx.
Can somebody please guide me to the right path, possibly share their Django sphinx docs workflow?
Thank you very much.

Does the static folder need to be checked in in Django?

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.

Django doesn't look for static files in my app

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.

Best way to (git) clone app into Django project directory

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.