Deploy static file of Django on IIS - django

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?

Related

Windows IIS 10 will not serve static files from Anaconda / Django 2.2 . . . How can I fix this?

The website displays to localhost without css, js, or images.
I setup Windows IIS according to this blog including the final section about static files. The methods outlined are similar to answers from this question, this question, this blog, and this youtube video on how to serve static files from django with IIS.
UPDATE: The problem may be coming from my virtual environment. This project was developed with Anaconda. When I followed the listed tutorials I simply used the paths to my conda venv and didn't think anything of it since the localhost loaded without errors. At the time python was only present on my machine in the anaconda environment, so if manage.py was able to execute and database data was accessed and displayed(without css/js) then I presumed this was not an issue. I am currently trying to interpret this blog on how to setup Anaconda for IIS 8.5 to see if I need to make additional changes to IIS 10. I have not had any luck using web.config files and have had to accomplish the same goals through IIS manager. Jalpa Panchal's comment lead me to investigate the environment.
Any ideas on what additional changes need to be made for IIS 10 to interpret an Anaconda(conda 4.8.3) developed django application?
ORIGINAL POST:
Django settings:
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, 'static') # tested in shell, it is where I expect at the same level as manage.py
The directory "static" was created with manage.py collectstatic in the expected STATIC_ROOT location with all of the static files contained
IIS Manager:
The static directory was then added as a virtual directory:
Then I removed the django handler I created from the static directory's handler mappings:
I unlocked the handlers at the root:
The django application did display properly, with static files, when I tried using Wampserver w/ Apache and mod_wsgi. Unfortunately, it appears windows IIS will be the better solution for other unrelated reasons. Not too mention Wampserver is a development server, not a production server.
I defined a path for the environment variable WSGI_LOG, the logs generated have no errors. Just states wfastcgi.py was initialized and will restart when there are changes to the files in my project
What else can I be missing that would prevent my static files from being processed?

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 restframework bootstrap static files

I have a regular django site, with djangorestframework (v2.3.14) serving restful api under "/api". On local box everything works fine (mac / mavericks), on remote box (Ubuntu 12) the API browser comes up but all the bootstrap stuff is missing (the page looks like it's out of 1992 prototype instead of pretty bootstrap theme i see locally).
All the pip dependencies have been upgraded and are identical. Locally running site through PyCharm, remotely it is running on WSGI.
What can I check to see what the issue is and resolve it??
I suppose that under PyCharm on your local machine you are running the development server, which serves static files directly from your apps and projects internal locations.
After every deployment into production (your WSGI server) you need to collect all static files to a single place, your STATIC_ROOT. This is a job for the django management command collectstatic, see Django docs here.
The command may look like this:
# Executing collectstatic (organize static files)
python /path/to/your/project/manage.py collectstatic --noinput
For further details you may also read Django cannot find static files. Need a second pair of eyes, I'm going crazy.
If this question doesn't help, you can quicly fix it making a link under your proyect's static folder
ln -s /your_env_folder/lib/pythonX.X/site-packages/rest_framework/static/rest_framework rest_framework

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.

Symlink to static html page 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/