1👍
I’d go with your second option. Yes, it’s some overhead with the two HTTP requests, but since both will be retrieving parts of your page, it’s not like you’ll be loading the same data twice. It won’t be much different from having an image file or javascript library referenced in the page (they also load as separate requests).
Unless you have different sets of information for logged-in and anonymous users, and you don’t want to load the anon info and then replace it with the logged-in one. In that case, load shared elements in the main page load, and always load variable parts via Ajax (different data depending on anonymous or logged in user).
1👍
Here is a different approach from my other answer. If you don’t like the if conditions in templates, I’d recommend using template inheritance. You can use e.g. a two-template approach, and you render one or another in your view based on user.is_authenticated
:
Have a base template with the page for the unauthenticated user (e.g. main_unauthenticated.html). Put all variable parts into blocks:
{% block userinfo %}You are not logged in yet{% endblock %}
Make a main_authenticated.html template that inherits from that one:
{% extends "main_unauthenticated.html" %}
And provide the variable blocks:
{% block userinfo %}Welcome {{ request.user }}{% endblock %}
As a general case template inheritance is more powerful than inclusion.
- [Answered ]-'UserForm' object has no attribute 'Cleaned_data'
- [Answered ]-Ajax post data in django1.5 ListView
- [Answered ]-Limiting user to single app
0👍
If they are not significantly different I would use option 1, if there were significant differences I think I would find it easier to maintain two templates for the two different conditions. You could alway use includes if large chunks were the same.
- [Answered ]-Django template if type add to html id
- [Answered ]-Submitting a django form via django-rest-framework and angularjs