http://127.0.0.1:4000/categories#update
I want this /categories/#update
but {{page.url}} only showing /categories
Related
I am creating a simple eBay like e-commerce website to get introduced with django. For removing an item from the watchlist, I placed two same links in two different HTML files, that is, I can either remove the item from the watchlist.html page or either from the item's page which was saved as listing.html. The url for both the pages look like this:
Remove from watchlist
Now, in my views.py, I want to render different pages on the basis of the request. For example, if someone clicked Remove from watchlist from listing.html then the link should redirect again to listing.html and same goes for the watchlist.html.
I tried using request.resolver_match.view_name but this gave me 'removeFromWatchlist' as the url namespace for both of these request is same.
Is there any way I can render two different HTML pages based on the origin of the url request?
Also, this is my second question here so apologies for incorrect or bad formatting.
You could check the HTTP_REFERER in the request.META attribute of the view to get the url that referred the request as so:
from django.shortcuts import redirect
def myview(request):
...
return redirect(request.META.get("HTTP_REFERER"))#Or however you prefer redirecting
https://docs.djangoproject.com/en/3.1/ref/request-response/#django.http.HttpRequest.META
I need to dynamically get the root URL from a page to set as part of the Open Graph tags that will fetch the desired image. The closest I got was with ${request.requestURL}, but it returns the whole URL, like:
https://localhost:8080/abc/123/example/example.jsp
But I would like for it to return just the root URL, like:
https://localhost:8080/
Is there a way to do this?
This is the header of a page that will be the product page of a e-commerce. So, I would need to get the root URL of whatever part of the website the user is in to fill in with the product-specific URL. I've tried lots of methods, like ${request.requestURI} and ${request.contextpath} but none of them return what I want.
Don't know if it's the optimal solution, but I achieved what I needed assembling the url like this:
${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}
Is there any way to get the url of current html page to convert it to PDF by this [https://www.npmjs.com/package/cordova-pdf-generator] ?
You can get the current URL with document.URL.This will be file:///android_asset/www/index.html#/current/router/path on an Android device. I do not know if the pdf plugin cares about the router path but you may have to split it like that:
let url = document.URL.split('#')[0]
To get the part without the router path.
I'm using the Twitter URL: http://search.twitter.com/search.json?q=%23test in order to return a JSON list of tweets with the hash tag #Test.
It returns 15 results and says page 1. How do I load the next page of 15 tweets?
*I tried adding &page=2 to the search URL, but no luck.
The JSON response of the URI you posted includes the query parameters to use to get the next page. It's in the "next_page" element. Currently, the value is "?page=2&max_id=80076124637499392&q=%23test". So, the complete URI for the second page is http://search.twitter.com/search.json?page=2&max_id=80076124637499392&q=%23test
The Twitter search API documentation unfortunately does not describe how to use this parameter, though it is briefly described in the Twitter API Wiki at http://apiwiki.twitter.com/w/page/22554664/Return-Values.
I'm paginating a list of items, and currently the page listed on page load is set by a GET variable (e.g. www.example.com/page.html?page=2). I want to switch it to ajax, but I'm worried users won't be able to bookmark the page they want to view.
Is there a way I can update the URL without redirecting the page?
Use hash
Your website is www.example.com/page.html
Part I.
When you load page two using ajax add a hash to the url
www.example.com/page.html#page2
You can do that using javascript
window.location.hash = "page2".
Now users can bookmark www.example.com/page.html#page2
part II.
When a user request a page say, www.example.com/page.html#page2
You can read the hash using javascript.
var myHash = window.location.hash
If myHash is empty load the page normally.
If it contains "page2", then load the content of page2.
Yes, with a hash in the url. You can learn more here.
You can also find a nice jquery plugin for that purpose here.
Regards