Mirco
Doragonsureiyā
Thanks
You're welcome! 😊
Mohamad Reza
Such a kind!
Fan / Ac
how login_required decorator redirects to login_url, i dont see any redirect function call here https://nekobin.com/huvowubale
Fan / Ac
Fan / Ac
ah ok got it
Mirco
Fan / Ac
is there an easier way to modify decorators other than creating another decorator with same code and adding my extra need to the code i need to set request.session["message"] = "authentication failed" before redirecting using login_required
Fan / Ac
Use a middleware
can you say more, i am not familiar with these things
Mirco
can you say more, i am not familiar with these things
You have the documentation by your side But basically you can write a custom Middleware that checks if the user is authenticated or not If not you set that message inside Session Middlewares are useful where you wanna do something everytime before or after a request
Mirco
ah ok, got it, for now i am using a custom decorator to do that, is that a bad practise
Not so clean, harder to maintain and extend You have to copy code
Fan / Ac
Not so clean, harder to maintain and extend You have to copy code
ah ok, at first i was using different url login/ loginfailed/ loginauthfailed/ then i changed to login/ and used session to pass the value
Fan / Ac
Which is the goal you wanna achieve ?
if a user tried to login and user cred is wrong display "login failed" in template login.html if a user tried to access to which that user doesnt have permission redirect to login page (which is login/) and display "acess denied" in template login.html sorry i dont know if i am clear enough i need url to be login/ in all case
Mirco
For the second one you need to work with permissions and you can use the user passes test or PermissionRequiredMixin
Fan / Ac
ah ok, i will look about this, basically what i am trying to do will be display different message in a template(here it is login.html) and in the same url(here it is login/) according to some condition(here it is based on user permissions)
Mirco
Study it on Django docs It's very simple
Fan / Ac
Study it on Django docs It's very simple
thanks will do, i just need to confirm one thing that i was doing, storing this message in session is not a bad thing right
Mirco
thanks will do, i just need to confirm one thing that i was doing, storing this message in session is not a bad thing right
Yeah but not needed because you can override what Django does and change the message it generates without using sessions
Fan / Ac
Yeah but not needed because you can override what Django does and change the message it generates without using sessions
i was worried if it was a bad thing to use session to store these types of message, happy to know it isnt, thanks i will read about overriding django auth thanks alot :)
Dominik
Hi guys anyone know how to solve this error : "You're accessing the development server over HTTPS, but it only supports HTTP." other than the methods I tried. I tried: deleting cookies/cache, restarted mac, set the settings that caused the issue to false. Nothing helped. # SSL Settings for Production SECURE_HSTS_SECONDS=0 SECURE_SSL_REDIRECT=False SESSION_COOKIE_SECURE=False SECURE_HSTS_INCLUDE_SUBDOMAINS=False SECURE_HSTS_PRELOAD=False CSRF_COOKIE_SECURE=False
Dominik
As mentioned I alread disabled the ssl configurations
Mirco
As mentioned I alread disabled the ssl configurations
Yes but I mean don't access it inside the browser with HTTPS Consider that new browsers' versions tend to go automatically to HTTPS before HTTP
Dominik
Before I set the settings I mentioned above all was working fine. When I runserver on a different port and comment out the settings then it works fine. But as soon as I uncomment the settings even though all are false it gives me the error. It always autoredirects to https
Dominik
I thought when I set the settings in my environmental file then I could use different .env files on development and in production where on development secure settings are all false and on production they are all set.
Mirco
Locally all the "secure stuff" must be off
Dominik
Even though they are off my browsers still remembers them. The only way to fix for me is to use different ports
Mirco
Are u sure it is using the correct setting ?
Mirco
And you have also PROXY HEADER set to None
Dominik
I haven’t set proxy header at all for now. Let me try that.
Dominik
And you have also PROXY HEADER set to None
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') this to none?
Dominik
still the same
Mirco
still the same
That's strange
Dominik
That's strange
It is, I will now just uncomment the secure settings (even though they are all on false) entirely and use a other port. I don’t find any other solution for now. Thanks for assisting 😉
Fan / Ac
You have to check user passes test
i was reading about user passes test, its first argument is test_func which is a function, actual_decorator = user_passes_test( lambda u: u.is_authenticated, login_url=login_url, redirect_field_name=redirect_field_name ) first argument is u.is_authenticated which will be a boolean value, what is happening here, is it referring to is_authenticated() a function that existed before sorry it was source code of older version, it points to the function i should check source code instead of docs, google search gave old doc and i forgot to check django version, edit: its the same in 4.0 too
Mirco
nothing so special
Mirco
i was reading about user passes test, its first argument is test_func which is a function, actual_decorator = user_passes_test( lambda u: u.is_authenticated, login_url=login_url, redirect_field_name=redirect_field_name ) first argument is u.is_authenticated which will be a boolean value, what is happening here, is it referring to is_authenticated() a function that existed before sorry it was source code of older version, it points to the function i should check source code instead of docs, google search gave old doc and i forgot to check django version, edit: its the same in 4.0 too
user_passes_test() takes a required argument: a callable that takes a User object and returns True if the user is allowed to view the page. Note that user_passes_test() does not automatically check that the User is not anonymous. user_passes_test() takes two optional arguments: login_url Lets you specify the URL that users who don’t pass the test will be redirected to. It may be a login page and defaults to settings.LOGIN_URL if you don’t specify one. redirect_field_name Same as for login_required(). Setting it to None removes it from the URL, which you may want to do if you are redirecting users that don’t pass the test to a non-login page where there’s no “next page”. it'd be clear enough
Fan / Ac
👍🏻
i am missing some function names when reading docs, i misread the lambda and i missed user_passes_test in login_required thanks for pointing it out
Jay
I am having trouble writing one query using ORM, I want to find the latest record in each group. I am putting chat messages in a group now I want to find the latest chat of each user and show chats latest chat of each user and with the latest user's chat on home screen just like in telegram. Currently I am using the following query, Chats.objects.all().order_by('user_id', '-date').distinct('user_id') Using this I am able to get the latest chat of each user but I am not able to get the sequence correct. The result of the query is in the order of which the users were created which I understand is correct, but I want to show the user who sent the chat latest at the top.
Andrey
<input class="form-check-input" type="checkbox" name="fartists[]" id="flexRadioDefault1" value="7"> how to get value by method get? i have error at page - Could not parse the remainder: '("fartists[]")' from 'request.GET.getlist("fartists[]")'
ꜱᴀᴇᴇᴅ
Hello, why does the photo not appear on the site? What should I do?
ꜱᴀᴇᴇᴅ
Doragonsureiyā
Fan / Ac
i am using Redirect View https://ccbv.co.uk/projects/Django/3.2/django.views.generic.base/RedirectView/ it takes post data from a html form and redirects appropriately a method in the class is def get_redirect_url(self, *args, **kwargs): if self.request == "POST": accept values from post then redirect based on condition if var: return reverse(urlname) else: return reverse(anotherurlname) what all am i doing wrong here
Fan / Ac
Илья
Hello! Can someone help me with such problem like, "colum <columnname> isn't exist" I change model in models.py, then makemigrations, then migrate, all ok ,but column not exist. wtf? I saw sql code, it is there, but not in db table. Thx 4 answers
Zerat
Hi everyone, I'm currently working on a custom Django Authentication. I'm trying to redirect user to the profile page after login / signup, with: return HttpResponseRedirect(redirect('user', user)) but that doesn't work, can anyone help? thanks anticipated for your answers
Vicky
How to schedule task from frontend means from user UI In Django
Zerat
How to schedule task from frontend means from user UI In Django
i would simply create a form that will take all necesarry input, and add the new "task" to the database. then add a custom view to run periodical checks for what tasks from db have to be done
sarth
hi friends, Please help, i want to bulk import data to database by make rest api in django...import file will be csv or excel. how to do this... please help...
Aniesh
will django and rest is capable for e-commerce ?
Aniesh
any project with django and ecommerce ?
Aniesh
😂
Charly
😂
It wasn't a joke