b
my problem is, when a new user registers, it gets all the data in the dB
Xavier
b
and all the users should assign their own new separate data as they continue to using the site
Xavier
b
b
model.py
b
decorators
b
from django.http import HttpResponse
from django.shortcuts import redirect
def unauthenticated_user(view_func):
def wrapper_func(request, *args, **kwargs):
if request.user.is_authenticated:
return redirect('home')
else:
return view_func(request, *args, **kwargs)
return wrapper_func
def allowed_users(allowed_roles = []):
def decorator(view_func):
def wrapper_fun(request, *args, **kwargs):
group = None
if request.user.groups.exists():
group = request.user.groups.all()[0].name
if group in allowed_roles:
return view_func(request, *args, **kwargs)
else:
return HttpResponse("you ain't authoizez where you wanna reach")
return wrapper_fun
return decorator
Xavier
Xavier
!paste
use pastebin
Doragonsureiyā
To share code or error tracebacks please use an online pasting service, here is a list of suggested sites:
- https://del.dog
- https://dpaste.org
- https://linkode.org
- https://hastebin.com
- https://bin.kv2.dev
Xavier
b
Xavier
Raffaele
unpopolar opinion: pycharm professional is the best IDE in the world
b
@login_required(login_url='login')
@allowed_users(allowed_roles = ['user'])
b
i did this in view
b
@unauthenticated_user
b
this on login and register view
Xavier
Xavier
Xavier
no one will do it except you
Raffaele
b
but the restrictions are working, also the unauthorized decorator
b
what I'm asking is, is this the right thing I did for my problems that I explained above or i should need to more
b
I've tried in many ways this code so still there's a problem in it I'll look into it
wanderer
Guys i deployed my webapp to heroku if i keep Debug=True it works
wanderer
but for Debug=False it show Error 500
b
wanderer
not working when debug is false
wanderer
says error 500
b
b
uploaded where?
wanderer
heroku
b
there maybe be something be showing up like, heroku logs tail
b
try that, it'll show where the error at
wanderer
no thats only for deployment errors i guess
wanderer
my webapp is succesfully deployed
b
b
that's what's debug False is for
wanderer
yes
b
and that's way to trace error, heroku logs tail
Anonymous
Rahul
How to update all field except one particular field in Django ?
Rahul
Please help me
Anonymous
How is your model set up?
Anonymous
Rahul
Anonymous
Yeah sure
Rahul
One table is there as a insurance type - gold, silver, and other
Rahul
And one user table in that table insurance type is foreign key
Anonymous
Okay
Rahul
So while registration user will select one insurance type
Rahul
Then while update user details we can change insurance type
Anonymous
Cool
Rahul
And once user will try then will throw error
Anonymous
So, it throws an error when you are updating the existing data?
Anonymous
Rahul
Anonymous
Oh
Anonymous
So use try except block
Anonymous
Catch the error
Anonymous
And pass it as a message
Rahul
Error is not coming
Rahul
If user will pass other insurance type then i have to send error msg
Rahul
How to handle in put api
Anonymous
Oh, so once a user of registered, they can't change their insurance type?
Rahul
Anonymous
Ohk