URL configuration in Django - python

I have a Django project in which the HTML page has a simple GitHub link.
Github
When I click on it, the URL it gets redirected to is "localhost/app/github.com"
Can you please explain why is it happening and what should I do to correct it?

This has nothing to do with Django, but is standard HTML.
You need to put the full URL, including protocol:
Github

Related

return http response redirect with destination url, python

Noob Here, I am having issues with my registration form in ajax and javascript. So I am seeing how to do a return httpresponse with a destination URL in a python script. I am not using django or flask. Does anyone know of a page that I can read to understand this topic.
Questions 1. Does this have any import dependencies?
2. Is this code correct down below? and if not what can be done to fix it. I want to send it to a thank you page.
return HttpResponseRedirect("url")
No. The code you have is a Django snippet and will not work unless you are using Django.
If you are not using any framework, then return a 303 See Other status code, along with a Location header with the URL to your thank you page.
The HyperText Transfer Protocol (HTTP) 303 See Other redirect status response code indicates that the redirects don't link to the newly uploaded resources but to another page, like a confirmation page or an upload progress page. This response code is usually sent back as a result of PUT or POST. The method used to display this redirected page is always GET.

Redirects in Django

I'm working on the Helpdesk module from Django.
I want people who try to access 192.168.x.xxx:8000/helpdesk/ are redirected to the login page: 192.168.x.xxx:8000/helpdesk/login/?next=/helpdesk/
I also want people who try to access an nonexistant page to be redirected to:
the homepage if connected, or
the login page if not connected.
I find an answer for the first part of my question. I just used the import login_required. Just before the function homepage in /helpdesk/public.py and the function index in /helpdesk/kb.py, I put #login_required(login_url='/helpdesk/login/?next=/helpdesk/) and it worked !
Now I try to find the answer of the second part (redirection).

Getting a URL in python2.7

In a Djano project, I need to get the complete URL of my web app in a view, along with the URL's anchor tag. For instance, if the URL is:
http://example.com/#section0
I need to get that in its entirely, including the #section0 part. As you'd already know, HTTP_REFERER doesn't suffice (which is what I've tried).
What's a good way to read URLs in python/django? Beginner here, please advise.
Sorry, but the anchor tag is never sent to the server. The only way a server could know what it was is if the server itself sent the user to a url with the anchor tag.
See here for more information:
Is the anchor part of a URL being sent to a web server?

Using ViewerJS with Django

I am trying to use ViewerJS in a Django 1.8.2 application. However, the link I am using will not render the PDF. I have the ViewerJS folder under static/js/ and my PDF under static/pdf/docs/. Here is the link I'm using:
Preview
The error I am receiving is a 404. Django passes back an error message "Directory indexes are not allowed here.".
Request Method: GET
Request URL: http://localhost:8000/static/js/ViewerJS/
Raised by: django.contrib.staticfiles.views.serve
If I go to localhost:8000/static/pdf/docs/agreement.pdf in my browser then the PDF downloads just fine. If I go to localhost:8000/static/js/ViewerJS/pdf.js then the pdf.js file downloads just fine. So I'm not sure why it isn't working.
Django's static server is only for development, and is purposely limited. As the error says, it doesn't deal with directory indexes.
You could probably make this work by making the link go directly to /static/js/ViewerJS/index.html.
I have just the same problem. I am trying to access a file located at static/gutenberg/docs/files/something.pdf in Django
The url I created is
"http://localhost:8000/static/gutenberg/js/ViewerJS/index.html/#/static/gutenberg/docs/files/something.pdf".
Inspite of adding index.html to the complete it wouldn't work.I am not sure why.
The path is right because I am able to download the file when I run "/static/gutenberg/docs/files/something.pdf" on my browser.

how merge string to open webpage

I want everytime people go to my website, it will automatically redirect to another website, say:
https://www.redirect.com/link?q=NEWSTRING
it sounds weird, but actually, what I want is when people load my page, it will trigger some scripts, in which it can tract "NEWSTRING" from some website, then put it to the link above to redirect my website there.
So what I have is a first part of the link, which is fixed:
https://www.redirect.com/link?q=
then
NEWSTRING
is obtained from my script, now how to write some thing that will redirect the webpage?
What I can think of is, write something in python.py, then rename it to .cgi, then upload it to my server at :
/home/xxxxx/public_html/cgi-bin/python.cgi
Will this make my website automatically load and redirect there ? Thanks a lot !
Why not just use straight HTML to redirect to the website you want? I might not understand your question correctly, but for example
<meta http-equiv="refresh" content="0; url=http://example.com/">
would redirect the user to http://example.com when loading your page.
What you need is an AJAX request.
When people load your web page, the page sends an AJAX request to some other site, and render your page after getting the request result.

Categories