Pycharm Can not find the reference to external javascript and css files - django

I am not able to locate my external javascript and css files when I ctrl click their path string.
My html template path is 'bodhitree-flipped/concept/templates/concept/content_developer.html'. And my external video.js file path is 'bodhitree-flipped/video/static/video-js/video.js'.
Any Idea how I make pycharm to locate my js files? I know the solution for this is to run python manage.py collectstatic command which will copy all my asset files to /staticfiles folder but I don't want to do it as it will increase the size of my project by duplicating all the static files.
I tried rebuiding the file index with option under File->invalidate caches/Restart... but unfortunately this also doesn't work.
This is how my project structure look like.
click on the file to see code in settings.py
Any help is deeply appreciated.

I have just changed the python template language from jinja to Django (settings->languages and framework->python template languages)and then invalidated the file cache. It worked.

Related

How does Django store it's staicfiles after collectstatic is run?

I need a bit of clarification regarding how Django updates its static files. Here is a hypothetical that will explain my predicament:
I'm working on my own website which requires a link to a PDF that is stored as a static file.
Later I replaced this PDF file, with a slightly altered name, and made corrections respectively in my code.
Then I run the collectstatic command to replace the old static files and everything works as expected. Explorer shows me that the old files have been properly replaced in their respective folders.
When I go to test the link I'm still forwarded to my old PDF file. The old staticfile as if nothing has been replaced.
Can anyone explain to me how this happened? I'm just concerned and a bit freaked out that my old static file is still being referenced. I mean it could just be a simple typo or I have a haunted static folder on my hands.
When collectstatic command is run Django searches for present static files in STATICFILES_DIRS and copies them into STATIC_ROOT path.
The link to file that Django returns - is exactly how it is set in code - Django will not search it this file is present to show the link.
Check or search your code for old file name, maybe it is left somewhere.
Also, static files usually are css, js, images - files used in rendering page. User content, data files (PDF file looks to be one of these) for downloading via download link - should be served as MEDIA FILES.

Django Mezzanine - Don't Overwrite Local Files with collecttemplates

I'm trying to copy over the mezzanine core files to my project using the following:
python manage.py collecttemplates
but every time that I run this is overwrites my local changes to files such as base.html. How can I run this but choose for it to only add missing files, not overwrite updated ones?
The command doesn't currently support this behaviour, but it's a great idea - I've just opened an issue for it here: https://github.com/stephenmcd/mezzanine/issues/1319
Meanwhile, to state the obvious workaround:
Copy your project's templates directory to an external temporary directory
Run collecttemplates
Copy the external temporary directory back to your project's templates directory

How to package an OpenStack Horizon Dashboard plugin correctly?

I am packaging a Horizon Plugin. I have a bunch of templates, a view, as well as css, js files, and images.
Everything should be contained so that the package is either a .deb or a tarball. So right now I keep all files in /opt/stack/horizon/openstack_dashboard/dashboards/<my-dashboard-name>.
My question is, how do I include js and css files properly? There is /opt/stack/horizon/openstack_dashboard/settings.py file that specifies HORIZON_CONFIG.js_files, however it is always empty! I put a list of files there, it still comes out as empty in the templates. So the question is, how do I include js and css files in a Horizon dashboard plugin, for the purpose of packaging it in either a single tarball or a .deb package?
You should store static files below <my-dashboard-name>/static. It's best to namespace your static files, I use the following directory structure:
<my-dashboard-name>/static/<my-dashboard-name>/js and so on for css and img then I reference the files in the HTML templates with /static/<my-dashboard-name>/js/jsfile.js, that way you won't get any name collisions.
When someone uses your plugin they extract your dashboard and register it in the right places and then additionally they have to run the collectstatic django management command from the base openstack_dashboard directory (in your case /opt/stack/horizon/), either:
$ ./run_tests.sh -m collectstatic
or
$ ./manage.py collectstatic
That should copy your static files to the right places according to how the site has been configured.

easiest way to load css and image file

I am trying to load a web design into django project on pyCharm. I created the URL in url.py for first page and its corresponding function in the view.py. On running the project index.html file is loaded only without images and css files. I have been searching for the solution but I could not understand any of them. Some of those said, place your static files into 'static' in the root directory of project. But in my html code, I have referenced them as css/main.css. In this case I might have to change all the code. Is there some easiest way to load static files? Please guide me step by step.
Here is the structure of my files in the project:
MyProject/template:
css/"all css files
js/"all java script files"
image/"all images"
fonts/fonts
index.html and other html files![error log:][1]
Follow these steps:
You need to create a static directory in your project root.
Specify the static directory in the django project settings.
Include the static files like css, js, image, fonts inside the static directory.
Change the static file's path in templates -- e.g. from /css/bootstrap.min.css to {% static "css/bootstrap.min.css" %}

How do I make django translate certain files?

I'm running django-admin.py makemessages -l es from within my app directory to create trnaslation strings. The result includes only those texts that are located in my app directory. My templates directory to that app is located outside the app's directory. How do I ask django to translate my template files too?
I didn't want to run the above command from within the project's dir, because my project contains certain folders that I do not want to translate.
Never mind, I found the answer. You have to create symlinks to the folders you want to get translated (i.e. templaets) and copy those symlinks to you apps directory and run the above command with --symlinks included.
If i understand correctly you'll need to use django's trans and blocktrans
template tags to translate certain strings of text.