开发者

How can i combine login to all the site with template inheritance?

1. I have a base.html template that just describe the site (the basic simple base.html) 2. I have a split_screen.html template that extends the base,html file and look like this:

{% extends "base.html" %}

{% block content %} - this is the part that changes in base.
    <div id="top"> 
        here come the login form and under it a logo and then a top nav pannel 
    </div>
    <div id="right">
        here come a static right nav pannel that never change, so there is no need for a block
    </div>
    <div id="main">
        {% block main%}
        this is the main part, this is the only thing that will change with every page in (all the files) that will extend from split_screen.html (every other page in the site).
        {% endblock %}
    </div>
{% endblock %}

OK, i guess that now is a time for a question... so, what i am looking for and can't find (or maybe just can't understand how to implement) is way to use template inheritance and still have this login backend view that i built (using email instead of username) implemented....I just can't figure this one out because every example i read i referring to log开发者_运维百科in as a page of its own, i need it to be embedded in this page (or don't i?).

Can any one please help with this?


OK, i've solved this problem, I didn't want to user the middleware and didn't use it, but by combining fe tutorials and tips, i think i got is all.

  1. build a main template (extends base.html) that will have amonge other things, the form
  2. build a mamber template that will inherit that.
  3. create a simple index view (in the main directory of your site, with nothing in it but the return render for the main template you build (for loaing the main page when site uploads
  4. second view is the backend for the login, with the authentication proccess "/backend.py" and will return the user instance of the user that did a success loging or None of not
  5. create custom login view that will get the request.POST for both the emain and the password fields (after checking that you are in a post - so you will not get bad resuilts and might and bouble posting and stuff like that) get the user instance from the backend auth method and check if not None and then if is_valid, if both go to memeber page, if not go to same page (will be get but default, so you will not have to put at the end of the view a redirect to render for this case (same level as the reques.POST if.

well, that is basicly it, now, every request will thrue this, no matter where i am becouse i extends that main template that we build in the beginning for the rest of the site...

for now it seem like it work perfectly, if any one has question or remarks i will be happy to hear them...10x

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜