Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I want a function which should run with or without a parameter.
This is my views.py
#api_view(['GET', 'POST'])
def enable_boards(request, board_ids=None):
```
This is my urls.py
path('enable_boards', views.enable_boards)
path('enable_boards/<str:boards_ids>', views.enable_boards)
Now I know I have to write re_path but I don't know how to write regex for this particular case. What should be the proper url in this case ?
Use url parameters instead of using it in the path.
For eg: https://127.0.0.1:8000/enable_boards?board_ids=[1,2,3]
And in view use: board_ids = request.GET.get('board_ids') for GET request and board_ids = request.data.get('board_ids') for POST request.
Happy coding
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm currently working on a small side project using the steam api, I want to check if the user inputs an url or not.
Could not find anything to this specific problem so if anyone knows that help!
Use regex
Sample Code Below:
import re
regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\"., <>?«»“”‘’]))"
def is_url(input_string):
return re.match(regex, input_string):
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to know that is it have way to make a tempory list that it can add by input field and not save to server until click some button like add to cart button. I will use this for POS system.!
[example similar to this]
(https://i.stack.imgur.com/wEvKf.jpg)
Django comes with Form Wizard which might helps you.
You can use sessions or cookies to store data, both methods have a default WizardView that takes care of storing the data for you.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is there any way to use firebase URL shortener(dynamic links) programmatically in Python Django?
There isn't a specific library, but you could call the REST API to generate links: https://firebase.google.com/docs/dynamic-links/rest#using_the_rest_api
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to add an email into a path in Django. I did this code but I don't know how take the variable called email after username place.
path('validate_email/<slug:username>/(?P<email>[\w.%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/<slug:token>', views.validate_email, name="validate_email")
You cannot use a regex with path(). If you want to use a regex you'll need to use re_path() or url().
It might be easier to use simply <email> in the URL pattern, then you can validate the email in the view.
path('validate_email/<slug:username>/<email>/<slug:token>', views.validate_email, name="validate_email")
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
this is my view
def mydate(request):
date = datetime.datetime.strptime(request.GET.get('date'),"%Y-%m-%d")
return HttpResponse(data)
and i want call this view in another method in the django project
how to deal with this problem ?
yup you can do it
like this
def other_view(request):
item = mydate()
// now do what you need to do