Django session doesn't work in Firefox

倾然丶 夕夏残阳落幕 提交于 2020-01-11 09:25:35
问题 I have a search view that saves some data in a session for another view: def search(request): ... if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): cd = form.cleaned_data melk=data(cd) request.session['data'] = melk request.session['form'] = form return redirect('/result/') ... def result(request): ... melk_list = request.session['data'] form = request.session['form'] ... When I use Chrome, everything is good. But when I use Firefox, it works fine the first time

Django: How to trigger a session 'save' of form data when clicking a non-submit link

我怕爱的太早我们不能终老 提交于 2020-01-06 05:08:06
问题 I know if want you to store form information to the session during a submit you do it with the 'def post' in your view. However, I can not figure out how to store form information when a random link e.g. 'homepage'. How would you go about storing form information when a user clicks away from the form? 回答1: To store information in the session, you don't really need to post, or submit some kind of form. You can do it anywhere, where you have request using session attribute. the session is dict

How do I properly unit test a Django session?

北慕城南 提交于 2020-01-04 02:43:08
问题 The behavior of Django sessions changes between "standard" views code and test code, making it unclear how test code is written for sessions. Googling this yields two relevant discussions about this issue: Easier manipulation of sessions by test client raises error for anonymous users I'm confused because both tickets have different ways of dealing with this problem and they were both Accepted. I assume this means they were patched and the behavior is now different.

Django add to cart and cart view error

霸气de小男生 提交于 2019-12-31 07:22:09
问题 I get a 'NoneType' object is not iterable error when I add 1 object to the cart via the scan_to_cart view and want to add a second object. Also I get the same error when I want to view my cart when there are actually objects in it. I could not find a common problem with a solution... Is the python version I work with the issue, or is there a logic or code error? Thanks in advance for suggestions/advice! models: from manageinv.models import Child User = settings.AUTH_USER_MODEL class

Modify session data of different Django user

最后都变了- 提交于 2019-12-21 23:05:16
问题 This may not be possible, but when certain conditions happen, I'd like to modify the session data of certain logged in users (flagging that some extra logic needs to run the next time they load a page). Is there a way to access the session of a user by their ID? 回答1: tldr; Query Session model, then modify matching sessions via SessionStore . Your question is twofold, how to get session of a user, and how to modify data of arbitrary sessions (possibly outside of view). Get all logged in user

Delete session key from all users

佐手、 提交于 2019-12-17 19:39:48
问题 When a user logs in some details are saved to the session, lets say using key='user_settings' When some updates happens within the system I need to loop through all users and delete the 'user_settings' key from each users session. That way I will trigger loading the details fresh from the database. How can I loop through all sessions and remove the key from each of the sessions? 回答1: Looping Even if your site has only a few thousand users, you might find that the django_sessions table has a

Django request.session does not resolve

喜你入骨 提交于 2019-12-13 06:17:07
问题 I have a ManyToMany relation between 2 of my models in the same app. This looks like following: class Event(models.Model): eventID = models.CharField(deafult = random_eventID) signal = models.ManyToManyField(Signal) .... .... Now, in my Form (using ModelForm) my eventID field is already populated with the eventID every time i refresh the page (because it gets a new random_eventID every time i refresh the page). This way when, in my forms i select to add a new signal (I want to be able to add

User authentication with mobile number and OTP in Django 1.7

走远了吗. 提交于 2019-12-13 00:42:07
问题 I have two types of users. - Customer. - Vendor. For Customers, I've already created custom user class where login happens through email and password. But, Vendors do not have email id and password. All vendor accounts are manually created by the django admin. Vendor class looks like this. class Vendor(): phone = models.CharField(max_length=12, unique=True, required=True) name = models.CharField() . . What's the best way to implement OTP login for Vendors? Vendors usually login through an

Django: Session created in database when login page loaded

[亡魂溺海] 提交于 2019-12-12 04:47:17
问题 My django_session table was growing very large and it seems to be due to a pingdom bot that I set-up hitting my login page. I tried creating a brand new django 1.4 app and the behaviour is replicated on any page that uses the django.contrib.auth.views.login page, including the default admin login page. This surely can't be the desired behaviour. Is it a bug? Is there a fix? (I have redirected the pingdom bot to another page that doesn't cause a new session to be created but I'd like to solve