So when I'm trying to pass url to django views it cuts it. For example, I have a webpage which shows statistics of downloads for users sorted by download amount. Then I want to get details about some user, for example for "Yousuke Kataoka". I press the link and go to user page. Url should be and is mysite.com/user/Yousuke Kataoka, but in the webpage I see "Details for Yousuke", it kinda cuts the url. So of course I can't get any details, because the username is cut.
Here is part of urls.py:
(r'^user/(?P<username>[*_a-zA-Z0-9./-=]+)', 'dq2.web.usermon.views.user')
And here is user.html template:
<html>
<head>
<title>Detailed information for {{usr}}</title>
<script src="/dq2/media/js/sorttable.js"></script>
</head>
<body>
<p>Detailed information for {{usr}}</p>
<table width="30%">
<tr><td>File Downloads (1HR)</td><td align="right">{{file_events_1h}}</td></tr>
<tr><td>File Downloads (24HR)</td><td align="right">{{file_events}}</td></tr>
<tr><td>File Downloads (7D)</td><td align="right">{{file_events_7d}}</td></tr>
<tr><td>File Downloads (30D)</td><td align="right">{{file_events_30d}}</td></tr>
<tr><td>Operations (1HR)</td><td align="right">{{op_events_1h}}</td></tr>
<tr><td>Operations (24HR)</td><td align="right">{{op_events}}</td></tr>
<tr><td>Operations (7D)</td><td align="right">{{op_events_7d}}</td></tr>
<tr><td>Operations (30D)</td><td align="right">{{op_events_30d}}</td></tr>
</table>
And so on..
What should I do?
Try adding a space in your regex. And are you sure you meant to have /-= in there?
Related
So I have this urlpattern where we could type a number on the address bar and it will render an html template which will display the entered number on the page, I decided to give it a little more functionality by piping an add:1 to a links href so that every time we click on the link it adds up to the previous number and then generate the response by displaying that number on the page, But I can't get it to work using django templating I keep getting page not found 404 error, Can anyone please help me with this? Here's is the url pattern which accepts an integer
urlpatterns = [
path('home/<int:num>',views.index,name='index')
]
Here's the HTML template
<!DOCTYPE html>
<html>
<head>
<title>Dynamic urls</title>
</head>
<body>
<h1>Page no. {{num}}</h1>
Change the page
</body>
</html>
the right way is to combine with statment with add filter before passing the new calculated variable to url as second parameter.
{% with num_=num|add:1 %}
Change the page
{% endwith %}
PS
there should be NO spaces around =
variables should NOT start with _
usual math ops (+) are NOT allowed just filters like add
This question is very similar to one I just asked href: Can I get Google search results to use/display the final redirect url?, but now the question is specific to Django.
My site has webpage urls that use the following format:
www.mysite.com/id/pretty_title
The front page links to these pages, but the href actually contains some parameters:
www.mysite.com/id/?some_ugly_parameters_to_let_me_know_what_search_it_is_from
This then redirects to
www.mysite.com/id/pretty_title
which shows the page.
My issue is that Google's search results show the link to the page as the ugly url instead of the pretty redirected one.
What I have learned is that I need to provide a canonical link. But how can I do this when the ugly url page never really exists, at least not as one that I have written?
What happens server side is that the view of the ugly url does a redirect:
return HttpResponseRedirect(pretty_url)
I think this is the correct built template tag that you're looking for.
{{ request.build_absolute_uri }}
You can just put it as part of the HTML returned from the Django template, in the <head> section.
Do you have a base.html in your Django? You can setup a {% block %} as a placeholder for the canonical URL and then set that value in each individual page that {% extends base.html %}
base.html
<html>
<head>
<link rel="canonical" href="{% block canonical_url %}{% endblock %}">
</head>
...
A lot of these proposed solutions have issues if (1) you want your www subdomain to be the canonical one and (2) there are URL params in the request path.
I would actually propose to hard code it in the base template and append request.path.
<link rel="canonical" href="https://www.example.com{{ request.path }}">
If you do end up wanting to use build_absolute_uri, I would do it as follows in your view (or you could create a template function):
canonical_url = request.build_absolute_uri(request.path)
Calling build_absolute_uri() without an argument will call request.get_full_path() and append that to your domain. If a user finds your site via https://www.example.com/?param=123, your canonical URL will include that param.
I have followed the steps in the documentation and it seems to be working as expected.
I have got an automated sitemap generated: https://duelify.com/sitemap.xml
Yet somehow there is no way to specify the title.
If I search in google for my site: site:duelify.com and scroll down I see the main site's title for every link:
Duelify | Duel Your Friends & Foes
https://duelify.com/topics/discuss/2/vegetarian-diet/
That doesn't look right.
If I try this with Stackoverflow:
site:stackoverflow.com django
Each entry has a proper title.
How could I achieve that? It is not clear from the given site map references.
The title displayed in Google search results has nothing to do with the sitemap.
Use meta (http://www.w3schools.com/tags/tag_meta.asp) and title tags:
<head>
<meta name="description" content="Your page description">
<title>Your page title</title>
</head>
And don't forget to set proper HTML heading tags.
I have the following HTML page which works perfectly fine as a HTML page; however when I try put it into APEX by entering the code into a Region it just goes all wrong.
When the submit button is pressed, it takes the user to a new page with the IFRAME on rather than just refreshing the page as it does in a HTML page. The other issue is the aesthetics, it looks perfect in Firefox but in IE the IFRAME is half way down the page. When investigating in Firebug I see no attributes which would cause this.
Is there a method of embedding a HTML page into an APEX form page?
<!DOCTYPE html>
<html>
<body>
<head>
</head>
<form action="http://ukserver/orderlist.asp" target="orderResults">
Enter Order Number: <input id="ord" type="text" name="ord" maxlength="50" size="20"/>
<input type="submit" value="Submit"/>
</form>
<iframe id="orderResults" name="orderResults" src="blank.html" width="100%" height="50%">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
This is the page in FireFox which as you can see looks ok.
This is the page in IE which is incorrect
Update:
The HTML page seems to work perfectly in the HTML header of the APEX page but its above my tabs and region which isnt the place where i want it. I tried to find an order (1112) and it returned the following 'File not found' which is correct.
Hi Tony, I created another IFRAME and i guess I'm half way there. I now just have to get the HTML form working, please see below:
It sounds like you have a PDF file in a folder on a server somewhere for each order. If the names of the files are predictable given the order number then you should be able to generate a link something like this:
1) Create an item to accept the order number e.g. P12_ORDER_NUMBER.
2) Create a button to submit the page
3) Create a report that displays when P12_ORDER_NUMBER is not null and selects:
select '//server/path/fileprefix' || :P12_ORDER_NUMBER || '.pdf' as url
from dual;
4) Convert the report column into a link via the column attributes so that clicking on it launches the file.
I've got the blog (http://loveclubhouse.blogspot.com/).
(1)
I added one like-button on top of my blog. This is global like-button for the whole blog. It's available from every page of my blog, so that users may express their attitude to the blog in general (doesn't matter which post of the blog they read at the moment).
<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Floveclubhouse.blogspot.com%2F&action=like&...></iframe>
I use facebook's Open Graph. So, when the user clicks on this like-button the story is created on his facebook's wall with the title, description, and preview-image that was previously defined in the Open Graph's Meta tags of my blog.
<meta content='DJ Club Mixes 2012' property='og:title'/>
<meta content='blog' property='og:type'/>
<meta content='http://loveclubhouse.blogspot.com/' property='og:url'/>
<meta content='Blog's cover image URL' property='og:image'/>
<meta content='Blog's description' property='og:description'/>
(2)
In addition to the global like-button I have also added standard "addthis" share-buttons for every post of my blog (let's say the user wants to share on his wall a certain post from my blog).
<div class='addthis_toolbox addthis_default_style' expr:addthis:title='data:post.title' expr:addthis:url='data:post.url'>
<a class='addthis_button_facebook'/>
...
</div>
<script type='text/javascript'>
var addthis_config = {ui_click:true, data_track_clickback:true};
</script>
<script src='http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4d68d12853670207' type='text/javascript'/>
However, when the user clicks on share-button for post, the facebook generates the story on his wall with the same preview-image and title that was set up for the whole blog.
The question is:
How to combine (1) and (2), so that the user may like my blog in general and the user may share specific posts on his wall with the title and preview-image for this particular post?
It's all about the OG tags on your page. When a user visits a different page in your blog, you need to be sure that the og:title and og:description (and og:image if you want) are updated to reflect the current article of your blog.