What is the best way to speed up the templates loading time? - django

I have a project in which I need to save or display multiple forms after saving data when the page load it takes several time to display whole content, please help me to suggest the good package of compressing static files, I have already used django-compressor and django-assets packages but didn't get any success.Any ither things I can apply here ??

What do you mean with 'it takes several time to display content', do you need to refresh your page multiple times or just it takes a few seconds to load the page?
If the rendering of the page takes a long time to render, you could try to find out why. Django debug toolbar (https://github.com/jazzband/django-debug-toolbar) is a good tool to get some insights to find some improvements.
If it's not possible to improve the rendering and most of the requests are made to the same form/data then you can take a look at the Django cache framework (https://docs.djangoproject.com/en/2.2/topics/cache/)

you can save the url of the static file in your database and using the url from the database you can load the files from the static folder . Also if it okay with your project you can use pagination

Related

Determine which templates are used by which views/ URLs in django

I have a fairly large django project consisting of several individual apps. I am farming out some of the front-end work (CSS, HTML tweaks) to people who aren't over-familiar with django. To that end I'd like to generate a list of templates for each URL pattern any given engineer is working on. This will save much time that would otherwise be spent manually tracking down the templates used during a view's render phase.
For example, if Bob is working on URLs beginning with /accounts/ then I'd like to generate a list of all the templates used by any view that handles requests to those URLs.
My initial thought is to use something in the test framework since that has access to the templates rendered during a request. However, I can't guarantee that all URLs or views will be exercised (sadly I don't have 100% test coverage), and a missed template is unlikely to be noticed. I don't mind writing a set of tests that simply exercise each view, but don't want to duplicate existing efforts. Also certain views require POSTed data or authentication to function correctly - although I suspect that's an issue I'll have to face no matter what approach is used.
Are there any utilities or snippets that will do what I need?
django-debug-toolbar is a must for developing with Django, It includes a panel detailing all templates used during a request.
I've found the SQL panel is the most helpful for improving page load times as it details slow and duplicate queries.
It can slow down requests when enabled, disabling all panels but those that you use helps.

Load X items until user reaches limit, then load X more items - Django

Using Django, and for example purposes, is there a way to load 50 pictures to start... Once the user reaches the end of the 50 pictures, load 50 more?
I would like to do this to decrease page loading time. If not, would anyone have a better suggestion?
I know you can do foo = Bar.objects.all()[:50], but then I'm stuck to only 50. I could see setting that for maybe 300, overall, if there are a lot of images, but is there a way to load them in increments?
Thanks in advance!
You can look into Django Endless Pagination. It provides Twitter- and Digg-style pagination, with multiple and lazy pagination and optional Ajax support.
There is another application infinite-scroll-pagination which might help you in implementing the infinite scroll like functionality.
Finally, there is one more library infinite-scroll. Its a jQuery Plugin which you can use but currently it is no longer maintained.

What is the best way to schedule a view render as a task in django-chronograph or similar?

The use case is I want to statically render a view daily. It seems like there should be a pretty standard way to take a view/template and render static contents daily without simply saying "write a custom admin command" or a relatively simple command template that populates a static file.
The reason is to remove a large volume of database queries to make a site lightening quick, even on a lightweight vps by only touching the database daily instead of on every page view.
If there's a better way to do it, I'm open to that. It just seems like the best way to do it is rendering static views on a regular basis and cache-ing the crap out of it before it even touches django.
There are several ways I know to solve this:
1. You can use Varnish (as described in this blog post). Yet this solution takes a bit more time to get into because it's side technology you'll have to deal with. Also it takes more efforts to maintain it.
2. More "django-side" solution is to use django-celery for daily rendering your view and storing it in cache. You can move all your static view logic into task and render it there once a day. In your view you can just get rendered response from cache and return it to user.
3. Also you can use django per-view cache and create task in celery to clear cache daily.

How do I show a spinning gif while just loading images in the templates/views, not actual data?

I have an ember site that is mostly static. However many of the pages have large high res images and image sliders that sometimes flicker when you navigate to a new page for the first time or load the site for the first time.
I was curious if its possible to use this feature: http://discuss.emberjs.com/t/found-a-fun-hidden-loading-feature/1677/5 on just images, not actual data from a server?
I created loading_route.js with one line:
Ew.LoadingRoute = Ember.Route.extend({});
And I created loading.hbs but nothing is happening.
Thanks!
I don't think you can do that with a Loading Route - but I don't see a reason why you can't do that using jQuery?

Caching data (image, rss) with django

That's my first question in here, I've been looking through old questions, but nothing matched with my problem. Here it is.
I'm creating some site with one main functionality. We want this site to display content of other sites, but in a specific way. User chooses let's say two pages from five and want to see their content. He clicks button 'Display' and goes to next page where he finds let's say view from web cam, and here comes problem.
I want to cache image that is hidden behind the url from which image was downloaded, so after refresh image won't be downloaded again, but browser will get it from cache.
I've been looking through documentation of Django, but nothing seemed to be useful.
I know that I should:
1) create table which stores cache
2) add to settings.py some CACHE_BACKEND = ...
3) use #cache_page(300) before declaration of function which returns content which should be cached,
but... it doesn't seem to work.
I will be greateful if someone tells how to solve that problem, maybe with some sort of code showing the mechanism.
Cheers,
Chris.
I think that right way to do this will be to store image somewhere on your server and delete it later with cron or something similar.
Django cache framework wasn't created for the purpose you are trying to use it.