django-views

Overriding Django views with decorators

喜夏-厌秋 提交于 2019-12-21 22:46:04
问题 I have a situation that requires redirecting users who are already logged in away from the login page to another page. I have seen mention that this can be accomplished with decorators which makes sense, but I am fairly new to using them. However, I am using the django login and a third party view (from django-registration). I do not want to change any of the code in django.contrib.auth or django-registration. How can I apply a decorator to a view that is not to be modified in order to get

Create django object using a view with no form

这一生的挚爱 提交于 2019-12-21 21:35:06
问题 I was wondering how I would be able to create an object in a database based the URL a user is going to. Say for example they would go to /schedule/addbid/1/ and this would create an object in the table containing the owner of the bid, the schedule they bidded on and if the bid has been completed. This here is what I have for my model so far for bids. class Bids(models.Model): id = models.AutoField("ID", primary_key=True, editable=False,) owner = models.ForeignKey(User) biddedschedule = models

Issues with feeding data into database when using for loop

怎甘沉沦 提交于 2019-12-21 21:32:37
问题 In my template I have used for loop for some fields <div class="register_div"> <p>Title:</p> <p>{{ form.title }}</p> </div> <div class="register_div"> <p>Upload Images :</p> <p>{{ form.image }}</p> </div> {% for item in product %} <div class="register_div"> <p>{{ item.Name }} <input type="text" name="custom[{{item.id}}]"/></p> </div> {% endfor %} <div class="register_div"> <p>Price:</p> <p>{{ form.price }}</p> </div> As code shows there is one field which using for loops if that field has

How to override my template instead of django admin panel for reset password?

天大地大妈咪最大 提交于 2019-12-21 20:41:18
问题 I am following this blog to reset the user password in Django. It is working perfectly. But the problem is that I want to show my template instead of the Django admin panel when resetting the password or confirming the mail. How can I achieve it? This is my urls.py file url(r'^password_reset/$', password_reset , name='password_reset_reset1'), url(r'^password_reset/done/$', password_reset_done, name='password_reset_done'), url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0

Advantages of using REST over simple URL and view creation in Django?

我们两清 提交于 2019-12-21 20:18:07
问题 It might be a silly question for many, but why can't I instead Create a view in django that takes a request and returns HttpResponse in, say, JSON format Map the view to a URL Hit the URL from my browser or another server and use the result? Thanks. EDIT - Two approaches: Import some djangorestframework or tastypie and build an api in my application which will throw json responses VS building a class based view and tell it to return json response . Is there any huge advantage of using the

dynamic file upload path with current instance id

风流意气都作罢 提交于 2019-12-21 17:26:49
问题 I have a form which gets current logged in user, some inputs and a file: class AddItemForm(ModelForm): class Meta: model = Item exclude = ['user'] For this form a have a view: item_form = AddItemForm(request.POST, request.FILES) if item_form.is_valid(): item = item_form.save(commit=False) item.user = request.user item.save() for this item's file field i am using upload_to feature. here is my modal: class Item(models.Model): user = models.ForeignKey(User) cover_image = models.FileField(upload

What does request.user refer to in Django?

冷暖自知 提交于 2019-12-21 06:51:03
问题 I have confusion regarding what does request.user refers to in Django? Does it refer to username field in the auth_user table or does it refer to User model instance? I had this doubt because I was not able to access email field in the template using {{request.user.username}} or {{user.username}} . So instead I did following in views file: userr = User.objects.get(username=request.user) And passed userr to the template and accessed email field as {{ userr.email }} . Although its working but I

Restrict `UpdateView` dataset for authenticated user in Class Based Views

六眼飞鱼酱① 提交于 2019-12-21 06:35:25
问题 I have a Django project where I extended the User to have a Profile using a OneToOneField. I'm using CBV UpdateView which allows users to update their profile. The URL they visit for this is ../profile/ user /update. The issue I have is that if a user types in another users name they can edit the other persons profile. How can I restrict the UpdateView so the authenticated user can only update their profile. I was trying to do something to make sure user.get_username == profile.user but

Restrict `UpdateView` dataset for authenticated user in Class Based Views

只愿长相守 提交于 2019-12-21 06:31:07
问题 I have a Django project where I extended the User to have a Profile using a OneToOneField. I'm using CBV UpdateView which allows users to update their profile. The URL they visit for this is ../profile/ user /update. The issue I have is that if a user types in another users name they can edit the other persons profile. How can I restrict the UpdateView so the authenticated user can only update their profile. I was trying to do something to make sure user.get_username == profile.user but

Django: ajax response for valid/available username/email during registration

三世轮回 提交于 2019-12-21 06:18:42
问题 I am using jQuery to do some inline form validation during user registration to prevent form errors after posting by checking to see if: username is available email has not already been registered The idea is to give the user feedback before the form is submitted to prevent frustration. The code is at the bottom. Questions: Is this a potential security problem? I had the thought that someone looking at my javascript could find the url I am polling for the username/email confirmation and then