I am new to this django middleware I worked with django middleware by adding login page on each selected requested page. But now I want to show a html form as user request any page. So what should I use process_view or process_response to call the template (i.e html form).
add a form that takes input from user yes or no if its yes then go to the view page else show HttpResponseForbidden(). And next time if user had saved yes earlier then skip this form.
Related
My problem is the following: i have a simple web app that requires a user to upload a file, submitting a POST request to the flask server.
If the file does not match the the requirements set by the application, the user is redirected to the same html page containing a form, and a message warning the user of their mistake is flashed onto the html page.
My problem is the following: currently the form is located at the bottom of the html page, but when the user tries uploading an unsuitable picture, they are redirected to the beginning of the page.
How do I tell flask to redirect the user to a specific section of the page (ie the section where the form is located in?)
you can try use id in your html simply add an id to the form then in your url add an #myFormId, if you'r using url_for do this
redirect(url_for("index")+"#myFormId")
also check this too.
Say I have two pages one is example.com/login and another page is example.com/admin
And when I put the credentials on the login page I get redirected to the admin page.
Admin page has a logout button. If I press that button then it redirects me to the login page again.
What I exactly want to do is, I want to display a message "Login again" dynamically (I know how to display a message dynamically) but only when user gets redirected from the login page via admin panel.
How can I do that?
You can do that either by:
Using Session:
upon logout you set a variable in the session, that this user has been loged out.
logout(request)
request.session['logged_out'] = True
Get parameter:
add a parameter to the redirected login url, if you find that parameter show you message, if there is no parameter you don't have to show.
redirect('login/?logged-out=True')
in both cases you have to check in your view, and add a a property to check with in your context.
I am developing ecommerce website in django .
I have view ( addToCart)
I want sure before add to cart if user logged in or not
so that i use #login_required('login') before view
but when click login it show error (can't access to page ).
Note that: normal login is working
Please check the following
1. Add login url on settings
2. Add redirect url on login required decorator
3. If you create a custom login view make sure to check next kwargs
Login required decorator is not working properly in the django, it will not redirect properly to the login page if user is not registered or logged in.
So in my django framework i made the login page other pages in the project.Now i want say if some other third party user try to run my any webpage on that specific time my website ask him/her for login before accessing my any website page,to resist that i used the login required decorator but when i logged in and copy my other webpage url and paste in the new window it will not show the login page just straight open that webpage in the new window.HOW DO I FIX IT????HELP ME OUT PLEASE.......
URLS OF MY WEBPAGES:-
path("loggedin/",views.loggedin,name="loggedin"),
VIEW PAGE:-
from django.contrib.auth.decorators import login_required
This is my index page where user can register his/her self and after that they will login and go to the next page......
def index(request):
return render(request,'userside/index.html')
And this is the page which comes after the index(main dashboard) page
#login_required(login_url='userside/loggedin')
##staff_member_required
def mainpage(request):
return render(request,"userside/mainpage.html")
The other webpage of my project
#login_required(login_url='/userside/loggedin')
def criminalsinfo(request):
crimins=Criminals.objects.all()
return render(request,'userside/criminalsinfo.html',{'crimins':crimins})
yes means in the same browser we open a new window
That means you are already logged in.
To confirm it, in your browser, visit your page and in cookies check if have sessionid or not. If yes, then it means you are already logged in.
Possible solutions:
Remove sessionid.
Use incognito mode.
Use another browser.
i'm new in Django.
I have a form once filled i keep the datas and redirect to another page, but i notice if i put the correct url i can access to this second page without passing by the first form.
here is my urls:
urlpatterns = patterns('',
url(r'newworkflow/$','access_mgmt.views.newworkflowform'),
url(r'newrole/$','access_mgmt.views.newrole'),
)
So if in my browser url i put /newrole i get the page but i want to have access to it only if the form on the first page "/newworkflow/ is filled.
Is it possible to restrict the access to the second page only if the first form page is filled?
Only by recording somewhere - say in the session - that the user has completed page1, and checking that in the view for page2.