How to get url parameters as a list in Django? - django

I want to get url parameters as list in django. Say for example, I will add each parameters to url as;
mydomain.com/param1/param2/param3/.../paramx
Where each param may be existed or not. For example a link may be;
mydomain.com/param1/param3/param4/...
So my question is, How can I get list of params in Django?
I tried handling parameters manually but since they are seperated it doesn't work as expected.

looking at the docs you should be able to use path https://docs.djangoproject.com/en/4.0/topics/http/urls/#path-converters
you then most likely have the path/string param1/param2... as a variable on your view

Related

How to pass a parameter date to url dispatcher but as named parameter

I've been reading lots of tutorials and stackoverflow questions, but I haven't found how to do this. I need to pass a parameter of type Date in a GET call on the URL.
I know it sounds easy, but I'm new to Django and what I have found is mostly something like this:
Django url that captures yyyy-mm-dd date
All those answers solve the issue if I want to have an URL like
http:www.myweb.com/2021/09/02
That is great if I want to write an url for a blog or website, but I'm doing it for an endpoint, and in my case, I need something like this
/some-action-endpoint/?created_at_gte=2020-01-01
So, I need to capture a parameter (hopefully named created_at_gte) with the value 2020-02-01 (It will awesome if I could capture that immediately as a Date object, but I'm fine with a string)
So, my questions are:
1.- It will be enough to create a group like this
url(r'^my-endpoint/(?P<created_at_gte>[(\d{2})[/.-](\d{2})[/.-](\d{4})]{4})/$', views.my_view),
Note_: by the way, the previous one is not working, if someone knows why it'll greatly appreciate it.
2.-The endpoint needs two parameters: created_at_gte and created_at_lte. How can I handle this? Do I need to add two url's to the url pattern?
I'm using Django 1.11 and Python 2.7. Cannot use other versions.
Query parameters aren't part of the URL matching behavior, so unfortunately your requirement to handle them as query parameters instead of URL path elements means you have to do more on your own rather than relying on pattern matching to reject bad requests.
You can do what you want as long as your base URL pattern (^my-endpoint/ in your example) is unambiguous and you're willing to handle the possibility that the parameters may not be set or may be set to something that doesn't parse as a date in your view, but you won't get the regexp-derived guarantees or the ability to bind them to view function parameters.
Instead, you'll have to extract them from the request.GET QueryDict object. That would look something like this:
In your url patterns:
url(r'^my-endpoint/$', views.my_view),
And then in your views:
def my_view(request):
created_at_start = request.GET.get("created_at_gte")
created_at_end = request.GET.get("created_at_lte")
# you now have no guarantees about these values except that if not None they'll be strings
# remember to do something appropriate for None, empty strings, strings that aren't dates, strings where end is before the start, etc

Export CSV file in ServiceNow using URL containing personalized list columns

I'm trying to export a CSV file in ServiceNow using the URL. I've applied my various filters and I've personalized the list columns I need. The problem is, when I use the URL to obtain the records, I get ALL the columns and not my personalized list columns. Can anyone tell me why this is happening?
The URL I'm using is as follows (sample, not the real URL):
https://abc.service-now.com/incident_list.do?sysparm_query=xyz
Can someone guide me as to whats missing in the URL?
There's a URL parameter sysparm_view that you can add to specify the name of the view you want to use, but it sounds like you may still be missing something.
There's a difference between "Personalizing" a list layout and "Configuring" a list layout:
The former ("personalizing") is a layout that is visible only to you.
There's no way to give a URL to someone that will give them that
particular list layout.
The latter ("configuring") is what you'll
need to use to define list layout configuration that is accessible to
any user, and which can be targeted via the sysparm_view URL
parameter
This wiki article defines views:
http://wiki.servicenow.com/?title=View_Management#Creating_Views
If you follow the steps in "Creating Views", you'll end up with a view name (as specified by you when you created it, say you called it kage77. Then you'd be able to send someone a URL with sysparm_view=kage77 and they'd see the list layout you associated with that view:
https://abc.service-now.com/incident_list.do?sysparm_query=xyz&sysparm_view=kage77
You have to include the file type as well like CSV/ XLSX/PDF
https://instance.service-now.com/incident_list.do?CSV
you can add few parameters,
&sysparm_query=active=true
&sysparm_fields=number%2Cshort_description
&sysparm_orderby=sys_id
More reference: https://docs.servicenow.com/bundle/london-platform-administration/page/administer/exporting-data/task/t_ExportDirectlyFromTheURL.html

Ember dynamic query parameters

I have what I believe to be common but complicated problem to model. I've got a product configurator that has a series of buttons. Every time the user clicks on a button (corresponding to a change in the product configuration), the url will change, essentially creating a bookmarkable state to that configuration. The big caveat: I do not get to know what configuration options or values are until after app initialization.
I'm modeling this using EmberCLI. After much research, I don't think it's a wise idea to try to fold these directly into the path component, and I'm looking into using the new Ember query string additions. That should work for allowing bookmarkability, but I still have the problem of not knowing what those query parameters are until after initialization.
What I need is a way to allow my Ember app to query the server initially for a list of parameters it should accept. On the link above, the documentation uses the parameter 'filteredArticles' for a computed property. Within the associated function, they've hard-coded the value that the computed property should filter by. Is it a good idea to try to extend this somehow to be generalizable, with arguments? Can I even add query parameters on the fly? I was hoping for an assessment of the validity of this approach before I get stuck down the rabbit hole with it.
I dealt with a similar issue when generating a preview popup of a user's changes. The previewed model had a dynamic set of properties that could not be predetermined. The solution I came up with was to base64 encode a set of data and use that as the query param.
Your url would have something like this ?filter=ICLkvaDlpb0iLAogICJtc2dfa3
The query param is bound to a 2-way computed that takes in a base64 string and outputs a json obj,
JSON.parse(atob(serializedPreview));
as well as doing the reverse: take in a json obj and output a base64 string.
serializedPreview = btoa(JSON.stringify(filterParams));
You'll need some logic to prevent empty json objects from being serialized. In that case, you should just set the query param as null, and remove it from your url.
Using this pattern, you can store just about anything you want in your query params and still have the url as shareable. However, the downside is that your url's query params are obfuscated from your users, but I imagine that most users don't really read/edit query params by hand.

adding parameter to wordpress url without query string

i want to have parameter in friendly urls way, have done it with query string but this is not what i want
below is my link
http://www.example.org/category-name/sub-category/post-name-goes-here
and want to have link in template like this
http://www.example.org/category-name/sub-category/post-name-goes-here/parameter
it should still load the same single page but with parameter so i can use condition in single page template
how i can ignore this using rewrite rule or any other method?
You will need to add a rewrite rule so it doesnt try and "solve" the url address using its standard function .
See my previous answers here:
Add "custom page" without page
WordPress Rewrite based on form hidden field
you can pretty much add anything to the url after that.

Retrieving all querystring variables from request object

In my django view, i have logic that retrieves a querystring variable called url from the request object like so:
link: http://mywebsite.com/add?url=http://www.youtube.com/watch?v=YSUn6-brngg&description=autotune-the-news
url = request.Get.get("url")
The problem arises, for example,when the url variable itself contains parameters(or variables)
link:http://mywebsite.com/add?url=http://www.youtube.com/watch?v=YSUn6-brngg&feature=SeriesPlayList&description=autotune-the-news
The feature parameter will be treated as a seperate variable. Since i don't always know the parameters that would be included inside the url variable, how can i force it to retrieve everything that comes before the description variable?
This is a URL encoding problem. Whatever technology is being used to generate the request needs to URL-encode the value for the 'url' parameter. This will make your link look like:
http://mywebsite.com/add?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYSUn6-brngg%26feature%3DSeriesPlayList&description=autotune-the-news
Now, Django will be able to parse the 'url' parameter completely without getting confused about the 'feature' and 'description' parameters. So, all you have to do is figure out how to get the UI technology used to create the link to encode that parameter.