I am developing a simple app using Django REST framework for the backend and with a Vue multi-page app as a front end. I use axios to make requests to Django from the javascript.
Locally, everything works well. All the pages work and login functionality works fine. For authentication, I am using Django's built in authentication and a store in Vuex.
However, once I started to deploy, it seems to break. To deploy, I initially decided to use ngrok to create an https tunnel to the backend. My frontend is still on localhost, but as soon as I change the url to use the new API, the login functionality stops working. The rest of the site (which does not require login) works fine, but the bits that do just don't work. When I click the login button, Vue tries to redirect me to the logged in 'dashboard' page, but then it identifies that I am not logged in and kicks me out.
The actual login process works and the server responds that I am logged in, but when the site checks again it responds that I am not logged in. There are no errors at any point.
I am happy to share any code that may help identify my issues, but I am not sure what to share at this point since I am not getting any errors!
Related
After deploying django app on heroku the url after every form submission or link in site been press resulting with "?next=" inserts into the URL address, I don't understand from where it comes and why heroku keep inserting them in a random way, running the application locally just working perfectly.
I've deleted the application from heroku and upload it again, the fault persists.
There's no http errors what so ever. If I keep submitting the form eventually will works.
For example: pressing the log button in the django admin console results with this URL: https://appname.herokuapp.com/admin/login/?next=/admin/login/admin/, hitting it quite a bit will finally make it work with the correct url display: https://mishnayot.herokuapp.com/admin/.
Switching from heroku postgres to AWS RDS postgres didn't help.
Help will be very appreciated.
When a user hits a page requiring authentication, they get redirected to the login URL with a ?next= indicating the page they were trying to access. This way, after they've logged in, they'll get the page they intended to access.
In your case, it seems like /admin/login/admin/ requires a login and the login is actually at /admin/login/. I'm guessing you have a bad link to /admin/login/admin/ somewhere when you intended to just have /admin/login/?
Well, struggling for days just to understand it's heroku backend issue and there's not enough information that could help me solving it (i did try to contact heroku support directly but I'm on a free account).
Finally I decided to deploy it using elastic beanstalk. The implementation took some time with long learning curve but now my site works and works great!
Thanks for trying to help Tim.
Cheers!
So I have set up Django rest framework as a backend API for an e-commerce website. The website is displayed through a React frontend, which is not served by the django backend.
I am currently running both the Django backend and the React frontend from their local development servers (http://127.0.0.1:8000 and http://127.0.0.1:3000 respectively). In the future they will be on separate domains, probably.
When I set a session in a view, and read the content in another, this works if I just type in the urls for creating and reading directly into my browser (just for testing purposes). But when I access the backend through my frontend, sessions can not be accessed anymore, or don't seem stored. What will happen is that I get a KeyError when trying to access the data that I set in a previous view.
I guess this has to do with something I have read about some time ago, but I find it hard to find the correct information on how to work with this. Does this have to do with the cookie with the session id not being available to the frontend, but only to the backend itself?
Main question:
I would like to know how I can work with sessions, using the above settup, for keeping a shopping cart.
My backend code, just in case someone wonders:
from django.http import HttpResponse
def cart_add(request, product_id, update, quantity):
request.session['one'] = 'created through "cart_add" view'
return HttpResponse("Created a session - cart_add")
def create(request):
request.session['one'] = 'created through "read" view'
return HttpResponse("Created a session - create")
def read(request):
print(request.session['one'])
I have removed some unnecessary code.
The cart_add view is called from the React frontend, using an ajax call (axios).
The create and the read view I called by typing their urls directly into the browser.
(This is all done for testing purposes, just making sure sessions are working before I start to write the real code.)
I've found a solution in another stackoverflow question. This is the link to it.
By adding the following to my axios request, the code works successfully:
axios.get('some api url', {withCredentials: true});
So it seems my assumption about the cookie with the session id not being available to the frontend is incorrect.
I also found out that I could see the cookie by opening the web page in Chrome, then opening the developer tools > going to 'application' tab > click on cookies.
Here all the available cookies are listed, and also a sessionid cookie is shown.
I had the same issue, by adding withCredentials in axios call didn't solve my problem in django 2.2.3 and axios 0.19.0.
If the answer here doesn't work for you, then look into the below answer :)
React Django REST framework session is not persisting/working
I am using Django Oscar Paypal for payment. I am having an issue with redirecting back to my website on the production mode.
I have successfully set up in the development mode and I have tried two different IP address for runserver : 127.0.0.1:8000 and 192.168.1.102:8000 -> both worked corrected and redirected to whatever server I was running.
I turned off Sandbox mode and I have a website that has https:// working correctly. I try to make a payment on mywebsite.com/ but it redirects to https://192.168.1.102:8000/checkout/paypal/preview/13/?token=******* when I am redirected to paypal website for payment and click on Continue. (This happens for cancelling as well).
I have checked the views in the paypal app and it has 'reverse' code written correctly. If I paste /checkout/paypal/preview/13/?token=******* part after mywebsite.com/, it seems to be working correctly.
Is there a way to redirect back to mywebsite.com/
Many Thanks
Kyu
I just tried to switch to sandbox mode in the production but it doesn't redirect me to sandbox paypal! It keeps going to proper paypal payment site even with sandbox API... I am getting confused now.
Could this be because I haven't done python manage.py migrate and makemigrations?
Oscar uses the Django sites framework to determine the appropriate return URL.
You probably have the wrong domain (192.168.1.102) configured on your Site.
Edit the site from the admin (at example.com/admin/sites/site/) to set the domain that you use in production. Once you change this the redirect from Paypal should work.
I am trying to use Siege to do stress testing on my django application. For static pages (e.g. landing page) it works just fine. However, 99% of the pages I want to test require that I be logged in.
How can I get Siege to login and test django views? The login page uses the Django Login form and view.
If it possible to test as one user logined in you can pass session cookie as Cookie header -H "Cookie: cookieValue". For more complicated scenario better to Apache Jmeter.
For basic HTTP authentication form, adding login=SomeUsername:somepassword to siege.conf directives worked for me. May be possible to use for other login schemes.
I created a Shopify app hosted on Heroku. I had to modify the name of the shopify app from shopify_app to shopifyapp for Heroku to recognize it as a Django app.
If I visit my app directly though app-name.herokuapp/login and connect the app to my store, It correctly pulls my recent orders and products.
If I visit the app through the app menu and it redirects to app-name.herokuapp/login/finalize it shows
KeyError at /login/finalize/
I haven't modified anything in shopify_app except changed it's name to shopifyapp everywhere.
I suspect since the app cant finalize, that is why the links like this also don't work:
https://{{ current_shop.domain }}/admin/orders/{{ order.id }}">{{ order.name }}
They just direct to something like
https://admin/orders/000000000
Can anyone help troubleshoot this problem with the shopify app?
I've made my app repo public since it's still essentially just the demo app:
https://github.com/dpetrillo740/scm
App is running at http://scmapp.herokuapp.com/
This was a bug in the demo App. I just fixed it with this commit 27d5091.
Update the path in your application url to /login from /login/finalize. The redirect_uri is now provided for authentication with shopify, so it will still redirect back to the finalize endpoint.