Django 1.9 admin not showing CSS style - css

I am new to django and currently I am making the tutorial. It goes well but every time at some point my admin site loses ist CSS styling and starts looking like this:
This problem is apparently not new, as I found few posts here (e.g., this one or this one) on the topic. Following the answers I made the next steps:
Running python manage.py collectstatic
Modifying settings.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Adding the following lines to manage.py:
import mimetypes
mimetypes.init()
mimetypes.types_map['.css'] = 'text/css'
Going sure that 'django.contrib.staticfiles' in settings.py is uncommented.
Nevertheless, nothing worked and my admin site still does not have CSS styling.
Note that in my case the problem is not consistent. Whenever I start a new project, the admin page is fine. The problem appears only after certain (and each time different) step throughout the tutorial. For example, last time it was after I modified the DATABASES entry in settings.py (though I went through this step smoothly one attempt before; changing the entry to its original value did not help to restore the admin page styling).
I am using django 1.9.6 with python 3.4.3 under Ubuntu 14.04.
EDIT:
I am running server with #DEBUG = True and ALLOWED_HOSTS = ['*']

Django does not serve any static or media files when DEBUG = False.
Changing the variable to True and the static files for the admin site will appear. Otherwise, you will have to use a web server program to server the admin files as well as any other static/media files included in your project.

Related

Wysiwyg image is showing up in media/wysiwy not inside pub/media/wysiwyg. How do I fix this?

Okay so I have a Magento 2.4.5 project where I am facing some issues like images not loading up because they are being looked up inside pub/media/wysiwyg instead of media/wysiwyg. I have some wysiwyg images inside pub/media/wysiwyg/<some_image_directory>, however on the live site the directories and files are showing up as media/wysiwyg. How can I make sure that a separate pub/media/wysiwyg directory is created in the live site apart from the media directory that is already there such that the image loads up properly? We are using nginx which is opening up at 'pub' directory as the root where the media directory resides. Any help is appreciated.
I tried checking for the piece of code where the image is coming from in an attempt to see if the path can be changed programmatically by removing the 'pub/' part from the pub/media/wysiwyg/ for the live site. However, that is not something that can be done as that will change things project-wide, which might break other things. Hence that is not being done.
First, you need to make sure that you are running the site from the root folder i.e. public_html on the server.
Steps to reproduce:
1: Run the command to load content:
bin/magento setup:static-content:deploy -f
2: Next command: chmod -R 777 pub/*
3: Set the secure base media URL and unsecure media URL from Magento database which you recently created and find the table core_config_data and change the path value as:
web/secure/base_media_url => https://example.com/pub/media/
web/unsecure/base_media_url => https://example.com/pub/media/
Or from Magento Admin
Stores -> Settings: Configuration -> General -> Base Url's -> Base URL for User Media Files
and to
Stores -> Settings: Configuration -> General -> Base Url's (Secure) -> Base URL for User Media Files
Flush Cache
4: Might be missing .htaccess in your /pub/media/ folder.
5: Check your .htaccess file, if there's bad code.
Thanks
Okay so I figured out the issue.
I was running the website from the pub directory as I should however there was a third party plugin which had some hard-coded src set by the owner for images set as /pub/media/wysiwyg in the adminHtml since they were using an older version of Magento which used to place images inside /pub/media/wysiwyg instead.
So I just changed it to /media/wysiwyg over there and everything works as expected.
Tbh the whole issue was quite hacky as the owner seems to have put a script inside the third party module's description section in the adminHtml and is using hard-coded links such as this.
Thank you all for the comments. :)

Django project does not work after being transferred from Windows to Mac

I'm using Django 3.1.7 on a MacBook Pro after transferring the Django project off of a Windows 10 machine. However, upon re-setting up the database and superuser and running the command pipenv sync to install all necessary modules, the server does run; but it doesn't serve any of my URLs or the CSS styles for the Admin page. I can reach the admin page at '/admin' but no other page that I've set up will display. All it gives me is my custom 404 page whenever I try to serve a page. Is there any way to fix this? Is something wrong? Where are the Admin CSS files?
python manage.py runserver --insecure
Use the --insecure option to force serving of static files with the staticfiles app even if the DEBUG setting is False.
djangoproject
I think we'd need more information... maybe the files itself.
There could be tons of things that could go wrong. Is your settings.py still pointing to the correct file paths? In views.py, did you make sure you are setting the html files in the same path? Are the html files in the right folder? Are all the Django and module versions the same? There's too much to name.
I have the same problem.
By what you are describing it happens because your file path uses either / or
One machine uses forward slash and the other backwards slash
I dont know to so use a method that work on both

Add Amazon Affiliate links to Netlify CMS Hugo site - markup unsafe=true

I created the default Netlify CMS site with Hugo to test it out. The first test I wanted to do was to get Amazon Affiliate sites to work. With my actual site, I had to edit the config.toml file to include:
[markup]
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true
In order for the tags to work.
However, with this newly deployed site, it's using the config.yml file. I tried to edit the file located here: theme-name/site/static/admin/config.yml . See the photo, below.
Nothing seems to work. However, in the preview pane, the ads show up without an issue.
Suggestions?
The problem was the path. I had to add this code:
[markup]
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true
to the [theme-name]/site/config.toml file.
There were at least two config.toml files in different paths. Also, there is a config.yml file. It was a matter of choosing the right path.

Django admin doesn't show CSS after deploiement DRF

I have build a web application using Django Rest Framework and React, I am using IIS for deployment. It works just fine but I have a problem when trying to deploy Django Admin. The style doesn't show. It shows this:
I have tried so many methods to add style to DRF project.
I used collectstatic and added it as application to IIS Manager
I activated mimetype in settings.py to accept .css
I tried to link css files in the to contrib/static with the /static url and added that into urls.py.
None of the above methods were able to solve my problem and I have stuck with this bug for days.
Could you help me to figure out this problem.
settings.py config
Your STATIC_ROOT seems to be incorrect. In fact, it will be the place where all statics will be collect by the collectstatic command.
So it has to refer to a path on your server.
You have two possibilities :
Build a relative path to a folder called "collected_static" or whatever name you want :
STATIC_ROOT = BASE_URL / 'collected_static'
Build an absolute path to a folder in your server like :
STATIC_ROOT = '/var/www/my_proj/statics
In development mode, you don't need to collect static, because django knows how to collect dynamically.
In production mode, you need to collect static, because it will provide and group all your statics inside the specified path.
After running python manage.py collectstatic, what is the response ? And can you see your expected statics in the expected folder ?

Django external css file problem

For a couple of days now I have been trying to setup my django project to run my html-template with an external css-file. So far, no succes....
I have installed staticfiles ( Im using django 1.2.4.) and put the 'staticfiles' in INSTALLED_APPS within settings.py and added the following code:
STATIC_ROOT=os.path.join(os.path.abspath(os.path.dirname(file)), "static")
STATIC_URL='/static/'
My css-file is located under /static/css/stylesheet.css
My html-template has the link
link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/stylesheet"
After running the server, the page loads just fine. However django cant find my stylesheet...
What am I doing wrong here?
The static root and url doesn't actually host the files. The static serve option (in the urls.py) mentioned previously is a good option for development and learning, but if you move to a deployment server you should use the static hosting provided by your webserver.
The way the static folders is intended to work is that you add the path locations for each app, project, etc to the static directories setting in settings.py. Then, when you run the command "django-admin.py collectstatic" django pulls all of your directories into your static root. After the first time you run collectstatic, only files that have changed will be copied again. This consolidates multiple static directories into one common place.
Static files documentation
You need to pass the RequestContext to the view, so it will run through the staticfiles' CONTEXT_PROCESSORS (which includes the STATIC_URL variable).
from django.template.context import RequestContext
context = {'my_other_context': 1}
render_to_response('your_template.html',
context_instance=RequestContext(request, context))
I would recommend you to just use a django.views.static.serve instance like this in the url.py file:
(r'^(?P<path>.*)$', 'django.views.static.serve',{'document_root': '/path/to/css/'}),

Resources