How can I do something like this:
def profile(request, pk=0 : int):
#to do
I need pk
to be int (without converting in function).
Like this:
def profile(request, pk: int):
If pk
empty - set value to 0 and type to int.
You can't really specify it directly in the argument field, but you can convert it right after the function declaration:
def profile(request, pk=0):
pk = int(pk)
#to do
It will throw an error if the passed value for pk
cannot be converted to an int
EDIT: I spoke too soon, apparently you can do exactly as you did, just change things around:
def profile(request, pk: int = 0):
#to do
BTW: I just did a quick research for "specify type of argument python". Please try to research easy things like so first before asking a question, you'll get an answer quicker :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With