Redirects in Django - python

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).

Related

Get Authorization Code From Callback Query

I'm currently working with the Spotify API. To work with it, I need to get the user to authorise and give permission for me to use their account data. After the user provides this permission, they are redirected to the Spotify homepage. In the URL of the homepage, they are taken to two query parameters including an authorisation code like so: https://open.spotify.com/?code=AQAKS1CbcTdK3...7JSQ.
How do I now get this code from the URL? I'm very new to this kind of programming so, if there is something I explained poorly, this is the link to where I got this info: https://developer.spotify.com/documentation/general/guides/authorization/code-flow/
Thanks so much to anyone who can help :)

URL configuration in Django

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

Use of Stripe payment gateway in django

I have installed dj-strpe module and register one user without any difficulty i.e., by submitting the form at /payments/ and here dj-stripe register the current user to stripe.com . But what if I want to send card information with the user and want to use it later , However I register the card by following instructions https://stripe.com/docs/tutorials/forms .
But I think this module must contain all this forms already but I don't found any thing in documentation to use them (how ever I find out urls and forms in this module) . So please tell me how I can use those forms in my project , is there any specific tags or urls to submit the forms.
For one instance I used this url /payments/history/ but I didn't show any thing in browser however I have checked the browser console and in response there is some html but browser is blank.
I hope I have explained my question. Any help will be appreciated.

Have user sign up with Google and get redirected back to the site afterwards?

I am using GAE with python and I can ask users to sign in with Google using:
loginURL = (users.create_login_url(self.request.path))
This gives me a link that lets users sign in and get redirected to my site.
However some users do not have a Google ID,
Is there any way to let them sign up for one and be redirected to my site?
I know there is no:
signupURL = (users.create_signup_url(self.request.path))
That is the kind of thing I am looking for, asking the user to sign up and have her quickly redirected when she is done.
Thank you very much for any insight.
When your user goes to the login url, there is a red SIGN UP button on the top. They can go sign up there.
It took me a second to find too, unfortunately you can't change the login page.
Actually, it is possible to direct a user to the subscription page.
It is just a little tricky:
The link you get to sign in looks like this:
https://www.google.com/accounts/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttp://study-wise.appspot.com/login&ltmpl=gm&shdf=ChULEgZhaG5hbWUaCVN0dWR5V2lzZQwSAmFoIhRSjkTO01_PtfPG9VN12NFsbyludCgBMhQrFIvLEm2lqCc65PvVrBca1skQRA
Where in my case: http://study-wise.appspot.com/login is the url of the application.
The shdf appears to be some key google uses to track the request. But I have not found any clues about it
Now the sign up link will be:
https://accounts.google.com/NewAccount?continue=https%3A%2F%2Fappengine.google.com%2F_ah%2Fconflogin%3Fcontinue%3Dhttp%3A%2F%2Fstudy-wise.appspot.com%2Flogin&shdf=ChULEgZhaG5hbWUaCVN0dWR5V2lzZQwSAmFoIhRSjkTO01_PtfPG9VN12NFsbyludCgBMhQrFIvLEm2lqCc65PvVrBca1skQRA&service=ah&ltmpl=gm
The url:
https://www.google.com/accounts/ServiceLogin
Was replaced by
https://accounts.google.com/NewAccount
and
passive=true
Has been removed. As far as I see no other changes have been made.
Here is the python function I wrote:
def login2Subscribe(link):
return link.replace('https://www.google.com/accounts/ServiceLogin', 'https://accounts.google.com/NewAccount').replace('passive=true', '')
You can use it like this:
viewVals['subscribe'] = login2Subscribe(users.create_login_url("/login"))

Determine if website developed with Django [duplicate]

This question already has answers here:
How can you tell if a site has been made with Django?
(7 answers)
Closed last year.
I actually have some questions (real childish).
1) If I know that a website has been developed using django , can we determine from the html source code (by right clicking and choosing "view page source ") , if that website has been developed using django?
2) If I have an HTML code for website written in HTML , and I just want to present it like that using django , how can present this HTML code using django?
3) For what kind of websites , should django be used or are used for ? I mean pure static page , blogs , or a simple google like .
Thanks in advance
Here are a few things you could use to determine if a web app was written in Django. None of these are foolproof by any means, but they could be indicators.
Try http://site.com/admin/ and see if it says "Django site admin" at the top.
Inspect all of the HTML source code of every form you can find on the site, and see if any contain an input tag with name='csrfmiddlewaretoken'. csrfmiddlewaretoken is Django's CSRF token identifier. Other web frameworks may use this same name, but Django is the predominant user of it.
Find information about the site owner and/or developer from a "Contact" page, Google their usernames/emails as well as the word "Django," such as "emailname#gmail.com django". If you see posts or questions about Django, this could possibly mean they use it often.
If all else fails, simply contact the site owner and ask them.
No, the source depends completely on the person who developed it, and there are no necessary "hints" that it was written in Django.
You should at least try the Django tutorial at https://www.djangoproject.com/, you'll learn the basics of setting up a Django application, and you'll answer your own question.
Django is pretty general purpose, a bit overkill for static pages. Anything else can be done in Django, the same way it can be done in Ruby on Rails or other Web frameworks.
Well, what you should do is to test the website behaviour in an unusal stiatuation, for example forcing it to return 404 or 500 error message, which developers often forget to customize.
If you for example go to http://www.galaxyzoo.org/ and then try to determine backend just by looking at HTML, you'll fail.
If, however, you try to access a page 'blablablabla' i.e. http://www.galaxyzoo.org/blablablabla then you'll see 404 message. If you paste the entrie text into google, you'll most likely get hits to Ruby On Rails... :)
Django leaves no trace on the html source unless you specifically do. If you only want a static site, django is overkill. Though if you really want to, have a look at django flatpages.
You could possibly try www.domainname.com/admin. Some people leave their admin at that url and you can see the login page.
If they left the login page as default, the title tag will say Login | Django site admin or something like that.
For example: http://www.snowbird.com/admin/ (no affiliation)
No.
Yes. See direct_to_template
See djangosites.org

Categories