Django restframework bootstrap static files - django

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

Related

Folders statics not found in server google - Django

Django cannot find the static files on the google server, the
python manage.py collectstatic
command has already been used with the settings.py configured.
To solve this problem I followed several tutorials that showed us how to deploy static files, including the documentation itself. However, none got results. It is worth mentioning that this same code and configuration worked in the homolog version of the system.

Heroku set default site

I have created a new Heroku site and I am developing it on my Linux box, using Django. The standard "getting started" site Heroku created for me is called "gettingstarted". How can I change that / configure Heroku to forget about it?
I was reading through the Django tutorial, which explains how to create a new site (django-admin startproject my_site). I did this successfully for a demo project. Then I tried to do it under the Heroku directory, because I wanted a better name for my site than "gettingstarted". I noticed that every time I start the Heroku server under my project, it says ...using settings 'gettingstarted.settings'. I found that this is configured in manage.py and I change it.
This is the directory layout I have
/some/path/heroku_random_name/gettingstarted/settings.py
/some/path/heroku_random_name/my_site/settings.py
/some/path/heroku_random_name/my_app
This is what I have in
/some/path/heroku_random_name/manage.py
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_site.settings')
so I would expect that the site that matters is my_site.
I got it to the point where I can run the site successfully on my local machine, and I can tell that it using the settings from my_site. But when I deploy the project to Heroku, it does not recognize my_app until I register it in gettingstarted/settings.py. In other words, when running in Heroku, it is still using gettingstarted as the site to run.
I am new to all this, so I left gettingstarted in the project, because I am afraid to break things. But how can I configure Heroku to execute settings from my_site and not from gettingstarted?
Found it: it's configured in Procfile.
It's confusing because it's configured in one place for running locally and in a different place for running hosted at Heroku.

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?

Deploying Django App on Heroku using Windows

I want to deploy my django app on heroku , which I have built on Windows machine.
Can I deploy the same application using heroku toolbelt for windows.
Or I have to setup all the things on a unix machine.
And one more thing the application uses Python 3 and Django 1.8
Will that be any problem.
There aren't any special process listed in the docs for windows usersYou should actually deploy from a unix environment, you have to create your Procfile, requirements.txt and make some changes to your settings.py file, it's easy and straight forward.
A step by step guide can be found here https://devcenter.heroku.com/articles/getting-started-with-django
Some problems you may encouter:
Internal Server Error heroku/django
Django migrations fail in heroku
Also make sure you add your migrations and cache folders to your .gitignore file.

Django site on Webfaction - how the flow of information works, and integrating with Pycharm remote dev

I have been learning Django in the development mode for a two months and I am up to speed with most basic aspects of python + django now. However, I was using the built-in runserver till this time
Now, I have got a Webfaction hosting account and wanted to know the following
1) Webfaction sets up the project with a certain Django version (say 1.6.4) and Python version (say 2.7) initially
The project directory (for say project MYAPP) is /<>/webapps/MYAPP
When the site is running in production mode, how does the apache server know which Python version, and which site-packages versions to use with the MYAPP source code to render the site?
I can see that the MYAPP folder has a lib/python2.7 folder, however when I am connected to SSH terminal, and do a "which python", i see :
which python
/usr/local/bin/python
so, do I take that this is the Python executable that is being used for rendering the website instead of the one in webapps/MYSITE/lib/python2.7 folder? How does the information/data flow about which programs to use during rendering the site with apache mod_wsgi work?
2) I was using a virtualenv in the development mode during testing. How do I use this on webfaction in production mode?
3) I am using Pycharm IDE. It worked well for the development mode. I can see that it has a remote interpreter configuration and a Deployment setting/option.
The python path that the remote interpreter settings tool detects automatically is the python executable at /usr/local/bin/python
Is this fine, or should I be pointing it to the more local python2.7 in the webapps/lib folder?
Thanks a lot of the answers and pls let me know if you need any supplemental info
Note to the OP: This should really be three separate questions.
1) For WebFaction, your Django app will use the Python version (and libraries, etc.) defined in:
~/webapps/<appname>/apache2/conf/httpd.conf
Specifically, you'll want to look at what is defined for WSGIPythonPath (which should mostly match up with WSGIDaemonProcess unless you modify the config and are doing something strange).
Note that which python just tells you what the default python is in your shell. This has nothing to do with the config file for the webapp.
2) You may want to expand on this as to exactly what your use case is and why the default Django webapp created by WebFaction doesn't fit your needs. But the short answer is:
Create a virtualenv on your WebFaction account.
Install Django, etc. into the virtualenv.
Edit the httpd.conf file I mentioned above to use your virtualenv instead.
I've done this with both a Django webapp made via the WebFaction control panel and via a custom mod_wsgi webapp. So it does work. Just make sure to use the right Python version when making your virtualenv.
3) I don't use PyCharm so I can't answer this (one reason why this question should be split up).