PythonAnywhere image not found - django

Before anyone deletes this due to the question being similar to others: Neither other questions nor the documentation got my site to work as intended.
The goal: Load images on my site
The problem: Image not found
Additional info: It works locally using python manage.py runserver
What I've done to try to fix it:
I've tried to follow the staticfiles guide https://help.pythonanywhere.com/pages/DjangoStaticFiles but this didn't work because I'm not using the default uploaded files handling.
I've tried to enter it under the PythonAnywhere > Web > static files tab but haven't been able to get that to work.
Tried a bunch of different solutions from the PythonAnywhere forum and SO forum and none got my site to work.
The site: http://nasablogdeployment.eu.pythonanywhere.com/
All code available here: https://github.com/MarkdenToom/NASA-blog
Static files directories here: https://imgur.com/xL0RN8A
WSGI file content: https://imgur.com/dJY4knp

Your web app is looking for the picture in http://nasablogdeployment.eu.pythonanywhere.com/blog/media/thumbnails/Touchdown_Expedition_62_Returns_to_Earth_Completes_Station_Mission.jpg while your current mapping resolves into url like that: http://nasablogdeployment.eu.pythonanywhere.com/media/thumbnails/Touchdown_Expedition_62_Returns_to_Earth_Completes_Station_Mission.jpg
Change your static files mapping so the /blog/media/ points to /home/nasablogdeployment/NASA-blog/blog/media/

Related

Django Admin Styling corrupted

I recently made some changes to my django site, one big one being upgrading from Django 2.2 to 3.1. Now my admin site styling is all messed up. I can't figure out what went wrong or how to fix. Any pointers would be appreciated!
See image of what it looks like after update....
The main home page for admin looks fine, but when I click on one of the models to view, the formatted is definitely not correct.
Also, some not all, of my images on the site are saying 404 not found...
It looks like your browser is caching the CSS / JS from the old version, you can clear your cache and reload. In chrome use ctrl + shift + r to reload.
I was facing the same problem, First I thought it was a Cache issue but it wasn't.
I checked the page source and found a css file being applied to the page which wasn't even present on my drive.
In my case the file was:
static/admin/css/nav_sidebar.css
So I created new file in static/admin/css named nav_sidebar.css,
then copy pasted the code which I got from page source and
added "display:none;" in the #nav-sidebar section(line:34) and [dir="rtl"] #nav-sidebar section(line:45 in my case).
You can find the Original code here by using Google Chrome's inspect tool.
Where to find the code
I had the same issue after bumping django from v3.0 to v3.1. I run python manage.py collectstatic to update css which solved my issue
I was experiencing the same styling as the OP's screenshots.
I had upgraded incrementally from 2.2 -> 3.0 -> 3.1 -> 3.2. I only experienced the styling issues in 3.2
The issue was that there were legacy admin styles committed to the repo in the static folder. To resolve, all I did was delete the committed admin styles, and Django then appeared to use its own styling
I was upgrading from 3.0 to 3.2 and I tried a couple of the answers here without luck. At the end, the following procedure solved it for me:
manually delete the content of the directory STATIC_ROOT (see in settings.py what you named the folder)
run the command python manage.py collectstatic This will repopulate the directory with the newst files
hard refresh your page (ctrl + F5)
I think the other answers here are necessary, but I'll add one more: You might have to bust caches in your server itself. In our example, nginx was configured to provide really long caches to our static files, so we just had to reset it to make changes come through.
Ok maybe I am late to the party but it may help others,
What works for me is:
Set STATIC_ROOT in settings.py (I guess it should be already there as project is old one)
Comment STATIC_DIR in STATICFILES_DIRS list (otherwise it will give error) and run python manage.py collectstatic
Clear browser cache.

Host Hugo website on github-pages

I created a static website using Hugo and I don't know how to host it on github. The documentation on their website didn't help me.
After finishing my website, I created the public folder which contains in theory all the files needed for the website (whith this command : hudo -t hyde-hyde). When I open index.html with chrome I only see the content of my website without the theme. Is it normal ?
Then I moved all the files within the public folder into my gihub repo username.github.io/ , but I can't see any result (I can only see my previous commit which is a simple Hello World).
How should I porceed to generate correctly my website and host it on github ? Thanks.
How to create with HUGO
If you have a problem while creating your site, check this tutorial.
How to Host HUGO website on GitHub (Pages)
Check this LINK where it shows you step by step all the procedures to host HUGO on GitHub, on both User/Organization Pages and on Project Pages.
Check list:
When I open index.html with chrome I only see the content of my website without the theme. Is it normal ?
I know it might seem a little too obvious, but check the spelling. Sometimes you spend hours trying to find the error and it's just a typo, this case in the theme you wanted to.
Have you tried another browser? It might not be the case, but checking it will get you out of doubt, also remember to delete the cache just in case.
Then I moved all the files within the public folder into my gihub repo username.github.io/ , but I can't see any result (I can only see my previous commit which is a simple Hello World).
Do you have a User/Organization Page (syntax: username.github.io) or a Project Page (syntax: username.github.io/project)?
UPDATE 1: Follow the instructions on this video for hosting on GitHub if unclear.
Could you add a link to your repo? Thanks.

Django-autocomplete-light does not show search box for selecting OneToOneField

I am trying to use autocomplete in admin page to auto select a field(OneToOneField) before saving, I am following the tutorial to add a field in admin.
I am not able to see the search box to type in my selections. I tried replicating the select2_one_to_one app from the test project: https://github.com/yourlabs/django-autocomplete-light/tree/master/test_project
I am see the same issue for this app as well. Attaching a screeshot of the issue
Screen shot of the select2_one_to_one app
After trying different things for couple of days. In Inspect I figured that the static files were not being loaded same as the demo project in the documentation (http://dal-yourlabs.rhcloud.com/admin/)
I had to update the STATIC_ROOT(Location used while running 'python manage.py collectstatic') folder and run the collectstatic command. The static files for autocomplete_light were copied to STATICFILES_DIRS. After this the autocomplete started working.
Documentation mentions we need to understand handling static files. So this is what they might have been referring to.

Uploading Python application for the first time. URLconfig URLS not working

It is my first time trying to get a Django application live on the net but I am having an issue with the URls.
The working local URL of my application is
http://localhost:8000/surveythree/ - This works as expected.
However when I upload my project to my hosting account I cant seem to locate the relevant page using the shortened URL as provided by the URLconf, in this case it should be /surveythree/
url(r'^surveythree/$', SurveyWizard.as_view([SurveyForm1, SurveyForm2, SurveyForm3, SurveyForm4, SurveyForm5])),
I can locate the page if I use the full filepath however.
http://www.mywebsite.com/bias_experiment/src/survey/templates/formtools/wizard/wizard_form.html
I thought the benefit of the URLconf was to shorten the URL to something like one of the following
http://www.mywebsite.com/bias_experiment/surveythree/
http://www.mywebsite.com/bias_experiment/src/surveythree/
http://www.mywebsite.com/bias_experiment/src/survey/surveythree/
Is there something simple that I am missing here? If anyone could tell me what the shortened URL should be based on the above it would be great. I have been trying multiple combinations for a while now but I don't know if I am going around in circles or doing it wrong.
Thanks in advance.
It doesn't look like you have actually deployed your site with a proper server. You can't just upload the files to any webserver and expect then to run: you need to configure a wsgi server and connect it to your app.
The documentation is here but to be honest I'd be amazed if your college server supported it at all, if all you have is a shared folder. You may be able to get it to work with FastCGI, but I wouldn't hold out a whole lot of hope.
(And even though you say that going to that long URL "works", I'd guarantee that all you're seeing is the raw HTML template. There's no way that any actual dynamic functionality will be working like that, as you'd see if you actually tried to submit the form at that URL.)
Deploying Django apps is much more complicated. To run in more "production" environment you will need to configure:
virtualenv to keep pip modules which your app required separate from global environment.
nginx for hosting static files ( you can copy them to some folder with ./manage.py collectstatic.
WSGI server: uWSGI or Gunicorn are both nice choices.
supervisor: for running and restarting WSGI and any other apps (for example celery) running in background
It's a lot for a start, so it's good to follow some tutorial and use ready to use config snippets.

CF10 developer on IIS7.5 / WIN7 - CFM files run ok - but can't see .GIFs

Can anyone help with this strange problem.
I have just installed CF10 developer on Win7 which is using IIS7.5.
Installation went smooth, and can browse .cfm files no problem and connect to datasources no problem .. BUT: even though I can browse all my local cf sites, none of the sites will display images or styles for external .CSS files.
So, I get the site, content from the database, and all the functionality of cfm files being parsed OK, but no styles and no images.
If I browse directly (pasting the filepath in the browser) to one of the images I get a 404 error - file not found - even though the .gif file does indeed exist in the directory.
So, basically, I can run CFM files, and browse a local site built in coldfusion, but none of the images or externally referenced css files will be "found" by the browser/IIS.
Can anyone help?
Thanks in advance if someone can..
Sounds like an issue with those mimetypes, please see the following for information on installing the static content role to IIS and enabling those mimetypes to be served.
No Mime Types Option in IIS 7
Be sure to enable static content in IIS 7.
Had two occurrences of this problem lately.
See here:
http://weblogs.asp.net/anasghanem/archive/2008/05/23/don-t-forget-to-check-quot-static-content-service-quot-in-iis7-installation.aspx
Try restarting the IIS server. Close all browsers and restart.
You need to determine if it is a CF issue or an IIS issue. Try the following:
Check to see if this is an issue with images not being served vs broken paths to the images. There may be CFML code that is creating links to invalid locations.
If the locations are valid then it would be an issue with IIS not server image files.
Also check to see if there is a similar issue with JPEG and PNG files. If JPEGs and PNGs show up, this suggests an IIS issue.
Also try creating a simple HTML page that has an image on it. If it has an image on it, this suggests a CF issue