Django documentation on development server using Sphinx CSS not working - python

I'm trying to combine Sphinx on my Django development server. I know i could better use apache. But I can't use apache due to the fact that the project will be managed by someone else and the project needs to work as simple as possible. Without too many external libraries etc.
So i tried django-docs package and django.static.serve in my url. The HTML pages work, only the look of the pages is just plain html so the CSS isn't included. The documentation on django-docs is really bad and i can't seem to get it to work with the static files Sphinx created. I can't use sphinxdocs as well since it needs haystacks which will add to my external libraries.
I added django-docs to my installed apps and added this to my settings. With projectpath being the path to where my conf.py is located. I'm not sure if the location is right though. But the documentation isn't really clear at what i should fill in on the project path part. And i added the urls in my urlspatterns
DOCS_ROOT = os.path.join(PROJECT_PATH, '../docs/_build/html')
DOCS_ACCESS = 'staff'
url(r'^docs/', include('docs.urls')),
In sphinx doc the static files are located in the docs/_build/html/_static

I found the problem If anyone else has the issue. I had some other folders called static inside my docs folder. When i removed them it worked. So it was just me being a bit stupid.

Related

Css file not loading on Python Anywhere

I have recently begun making a Django project on PythonAnyhwere.
I have followed the entire tutorial provided by Django for including static files on the project. I have observed the programs work fine on a site with http, but does not work on a site with https.
What could be the reasons and how can I overcome this problem?
Edit : The site is working now, apparently, but I would still like an explanation as to why it WAS working differently, if anyone can provide.
to load your CSS files (or totally static files), you need to follow the steps below:
1- inside settings.py
STATIC_URL = '/static/'
STATIC_ROOT=os.path.join(BASE_DIR,'static')
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
MEDIA_URL='/media/'
2-collect static files using bash console
python manage.py collectstatic
3-you need to enter the Static files directory inside the web tab
check the image below
static files python anywhere
4- reload your web app

Django: unable to locate static files folder

I am trying to setup an AS2 server using the python package django-pyas2 (https://github.com/abhishek-ram/django-pyas2)
Everything has been working fine while I was using the runserver command, but when trying to host my web app using IIS(10), I've noticed that none of my static files get loaded when loading a page.
I've been on countless forums/documentations and I know that I need to setup my IIS to serve these files, but I haven't been able to answer a rather stupid question:
Where is the /static/ folder of django-pyas2 located ???
There is no such folder on the github page.
When using the runserver command, django somehow manages to find all the static files (.css, .js, .png) from the static folder, but I am still totally clueless to where that folder is actually stored.
I've been searching in these locations to no avail: (I'm using a virtual env on Windows Server 2016)
my own project
my venv's site-packages\django-pyas2 folder
in C:\Python37\Lib\site-packages\django-pyas2
in C:\User\AppData\Roaming\Python\Python37\Lib\site-packages\django-pyas2
I've also tried to use the command collectstatic, but I first need to know where the actual /static/ folder is stored.
I've double-checked, and the files are apparently stored locally and not on a CDN. This is driving me kind of nuts, and I could definetly use some help from someone!
A big thanks in advance ❤
EDIT:
my IIS wfastcgi configuration
my IIS advanced settings
I'm not sure about how IIS(10) works but this is usually the fix.
go to settings.py and add a path for your static files.
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')#new
Next on the console (command prompt/ terminal/shell) run
python manage.py collectstatic
This should work
OK, so I finally found the static folder I was looking for in this location:
<PYTHON_PATH>\Lib\site-packages\django\contrib\admin\static
I believe the django_pyas2 package is using some default js/css already included with Django, and I couldn't find it because it was burried in Django's files.
For those encountering the same problem, here are the steps I then took to make it work with IIS(10):
copy/pasted the static folder from the django package to my project's root
went to IIS manager, right clicked on my website > Add Application
for the application alias: "static", for the path: <path_to_static_folder>
/!\ IMPORTANT /!\ left clicked on newly created "static" application, went to Mapping Manager, and then deleted the associated FastCGIModule
Didn't have to do anything in settings.py, nor execute the collectstatic command.
Works fine after that!
Thanks for trying to help.

Itegrating django-disqus on a https site

I'm using the django-disqus package (https://github.com/arthurk/django-disqus) on my web site which works great in dev. However my production server is running on https and when I view the page I get an error and the disqus comments are not loaded. The error shown in the console states that the code is blocked as it is trying to run insecure content from ...discus.com/count.js and ...discus.com/embed.js and the content should be loaded over HTTPS.
Does anyone know how I can solve this? I've had a look at the docs http://django-disqus.readthedocs.org/en/latest/ but cant find this mentioned.
Edit 2 (July 15, 2014):
The newest release of django-disqus has been uploaded to pypi and can be installed through pip or easy_install. This includes templates that use protocol relative urls, so it may now be easily used on sites served from HTTP or HTTPS.
Edit (July 4, 2014):
I've contacted the repository owner and gotten access. The latest merge into master supports protocol relative urls. It can be installed directly from github using pip:
pip install git+https://github.com/arthurk/django-disqus
Original Answer:
Just taking a quick look at the code for django-disqus on github
https://github.com/arthurk/django-disqus/blob/master/disqus/templates/disqus/show_comments.html
It looks like the http protocol is being hard-coded. There is already an open issue on github to support this, however it doesn't look like the code has been touched for a while, which means the author probably isn't interested (also, there are 10 open pull requests, which isn't a great sign either).
https://github.com/arthurk/django-disqus/issues/18
Your easiest solution is this:
In your settings.py file, make sure your template configuration is something like this (I do this on all my projects, so I can easily override the templates in some 3rd party apps, by providing an alternative template in my site:
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATE_DIRS = (os.path.join('path', 'to', 'mydjangoroot', 'myprojectroot', 'templates'),)
Find the django-disqus package on your machine and copy the 'templates' folder, into the same folder as your settings.py file (if you do something like what I've displayed above)
If you just want to use HTTPS, it's a simple matter of opening the template files modifying the protocol used from HTTP to HTTPS.
Why this works
When do you something like call one of the functions that renders a template, (like django.shortcuts.render).
Django uses a series of template loader classes to figure out where exactly your template is located.
The filesystem.Loader, that I have specified first, will first use any directories I have listed in the tuple assigned to TEMPLATE_DIRS.
Second, if the template wasn't found the app_directories.Loader, it will search any of the installed apps, under a subdirectory called 'templates' for a path matching the template requests. This is usually the behavior I prefer, so, as I mentioned above, I can override the templates for a 3rd party app directly from within my project.

js and css files are not read in a DJANGO project

I am reformulating a previous question because I think it was formulated as a Python problem but it is a Django one.
I am installing a project from github called publicmarkup:
The main page displays on the browser but no media (neither js files, nor css files) are read loaded. There is a module called mediasync that seems to be necessary to display correctly the css and the js files of the templates.
I think this a configuration problem. Here's the link settings.py file, Here it could be find the root path of the media folder.
And here's the doc for the mediasync modulet explains how to configure static_url
But I didn't understand anything since I am a newbie to djnago
In Django you have to set up your own workstation serve static files, in both dev and live modes.
You can read about it here.
This explains how to serve static files in your dev environment.
In live mode you serve your static files directly via your end web server, usually either Apache or Nginx.

How can I use Bootstrap with Django?

I'm learning python and Django coming from PHP. This is all really exciting, and I would love to use Bootstrap with Django to create sexy web pages.
As I understand it (I'm following the Django tutorial on their website), Django uses "apps" which can be included in your settings.py file. I did a quick search and found several bootstrap-themed apps, but have no knowledge on how to pick the right one. Is there a standard app most people use? All I need are the bootstrap.css and bootstrap.js files.
I'm sure I could manually place them in my root, but I'd enjoy an "all inclusive" setup within my Django install.
Re-reading your question, it seems that you're searching for a way to install Twitter Bootstrap as a Django app. While there are some apps out there that facilitate using Twitter Bootstrap with Django, you don't really need to use any of them.
You can simply include the Twitter Bootstrap CSS and JS at either the project or app level and refer to them in your Django templates.
To include Twitter Bootstrap in a Django app, your best bet is to:
Use Static Files
In your settings.py, add the path to Bootstrap (which you should download and place in your Django app under a folder named static:
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/path/to/my_project/my_app/static/',
)
Also, make sure your STATIC_URL prefix is set:
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
Now, download Twitter Bootstrap and place it in the path there:
/path/to/my_project/my_app/static/bootstrap/
Include Twitter Bootstrap in your templates
I would link to Twitter Bootstrap documentation, but there isn't any, really. Your best bet is to take a look at the source of their starter template. Using the Django templating system is a bit beyond the scope of this question, but I'll give you this hint: Anywhere in the starter template where you find a link to a .css or .js, replace it with your STATIC_URL.
So:
<link href="../assets/css/bootstrap.css" rel="stylesheet">
becomes
<link href="{{ STATIC_URL }}/bootstrap/css/bootstrap.css" rel="stylesheet">
I use the starter template as my base.html and include {% block content %} blocks in base.html that can be replaced by the actual content in my templates, which {% extend base.html %}.
Or, use a 3rd party app to guide you
You might investigate is the Django Bootstrap Toolkit, which I have not used myself. I would suggest doing it yourself manually first, however, as a way to explore the project and to really understand what is going on. It's not too hard at all!
Welcome to the world of Python/Django. Like you, after years of doing web development in PHP, I've migrated to creating dynamic websites and robust web applications using this language/framework pair.
One of the really nice features of django is their automatic admin interface. I use an app called Django-Admin-Tools and django-admintools-bootstrap which transforms the default interface into a slick looking admin. https://bitbucket.org/salvator/django-admintools-bootstrap
The easiest way to install django apps or other python modules is by using pip. I would read up on using virtualenv http://readthedocs.org/projects/virtualenv/ to manage your django projects. When you set up a python virtual environment, it allows you to install django apps and python modules in a separate python install on your system.
Then, installing additional django apps is a breeze - pip install django-admin-tools - django grappelli - south - are all some of my favorites.
What if you simply install twitter-bootstrap using pip:
follow the instructions:
https://pypi.python.org/pypi/django-twitter-bootstrap/
for the simple configuration.
None of the mentioned answers worked for me, the simplest way of all I will say is directly add CDNs in your base.html which will be used to extend and you can add it in standalone/static pages as well
Read here for the bootstrap CDN and integration.

Categories