2

I have a web app where users can have profiles (somewhat like facebook) and they can view their own profile as well as other peoples profiles. What you would see in your own profile would be everything, but someone else viewing your profile might not be able to see everything on it.

In order to accomplish this, I have common-profile.html and profile.html where profile.html includes common-profile.html and common-profile.html is what everyone can see. So if I want to view my own profile I would see profile.html but someone else would see common-profile.html.

The problem is that when I use template inheritance, both of those templates inherit from some base template so the template gets imported twice.

profile.html:

{% extends 'base.html' %}

{% block content %}
{% include 'common-profile.html' %}
...other stuff would go here
{% endblock %}

common-profile.html:

{% extends 'base.html' %}

{% block content %}
<h1>{{c_user.first_name}} {{c_user.last_name}}<h1>
...other stuff would go here
{% endblock %}

Is this just a bad idea? Should I just have one profile and check permissions/use some if statements in template tags? I don't want to have too much logic in my html pages but if it's just some if statements to decide what to show, maybe that's ok?

1 Answer 1

6

What about instead of using an include, you made profile.html extend common-profile.html? Then just have an empty block in the common profile template that the non-common-profile template can add stuff to. Something like this:

common-profile.html:

{% extends 'base.html' %}

{% block content %}
    <!-- Normal common profile stuff -->

    {% block extendedcontent %}{% endblock extendedcontent %}
{% endblock content %}

profile.html:

{% extends 'common-profile.html' %}

{% block extendedcontent %}
    <!-- Special profile stuff -->
{% endblock extendedcontent %}
Sign up to request clarification or add additional context in comments.

2 Comments

Yea that would definitely fix the problem. What are your thoughts on having two separate html files rather than one that just says "if you have permission to see this, here it is"
Well, if privacy is a major issue (which it typically is for sites like Facebook, et cetera), having two separate files reduces the chances that a typo will result in the accidental revelation of personal information that was supposed to be private.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.