django-views

'module' object is not callable Django

被刻印的时光 ゝ 提交于 2019-12-13 11:06:05
问题 views.py for user in users: #for profile in RegistrationProfile.objects.filter(user=user): #if profile.activation_key_expired(): salt = sha_constructor(str(random())).hexdigest()[:5] profile.activation_key = sha_constructor(salt+user.username).hexdigest() user.date_joined = datetime.now() user.save() profile.save() #if Site._meta.installed: site = Site.objects.get_current() # else: site = RequestSite(request) profile.send_activation_email(site) context.update({"form" : form}) return render_to

how to solve django: UnboundLocalError

安稳与你 提交于 2019-12-13 09:28:24
问题 I have the given view and template code, when i try to run this code i get the following errors.when i searched about this type of error,i found that it happens when a variable and function is given the same name,but could't correct it in my code. Environment: Request Method: GET Request URL: http://127.0.0.1:8000/budget/show/ Django Version: 1.2.5 Python Version: 2.7.1 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib

Django formset only adding one form

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 08:15:35
问题 OK, so this is my first time using formsets. I am trying to create a table that I can dynamically add rows to and fill out each row, then submit and have Django put them all in the database. Every time I submit it only adds the first form. File views.py: @main_context_wrapper def bacteriaForm2(request,context): if not request.user.is_authenticated(): #If user isn't authenticated, then just redirect to login return HttpResponseRedirect('/login/') BacteriaFormSet = formset_factory(BacteriaForm)

How to post a array to views.py

雨燕双飞 提交于 2019-12-13 07:56:37
问题 I am using for loop in my template and for different id of each record i am using arrays {% for item in product %} <div class="register_div"> <p><label for="id[{{ item.id }}]">{{ item.Name }} </label> <input type="text" name="custom[{{item.id}}]"/></p> </div> {% endfor %} Now when in my views i want to save this data to my database.But firstly i checked that whether my array return something or not.So i just try print that as. q = upload_form.data['custom[]'] or q = upload_form.data['custom']

Class Based Views (CBV), CreateView and request.user with a many-to-many relation

牧云@^-^@ 提交于 2019-12-13 07:26:05
问题 Based on the examples from https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-editing/#models-and-request-user - but with a many-to-many relation instead of a foreign key relation: models.py from django.contrib.auth.models import User from django.db import models class Author(models.Model): name = models.CharField(max_length=200) owners = models.ManyToManyField(User, related_name='owners_') views.py from django.views.generic.edit import CreateView from myapp.models import

performing different functionality on modelform buttons django

倾然丶 夕夏残阳落幕 提交于 2019-12-13 07:24:05
问题 I have a modelform with 2 buttons and i want to perform different functionality on them. My modelform: class jobpostForm(ModelForm): class Meta: model = jobpost fields = ('job_title','job_type','job_location','job_description','start_date','end_date','country','how_to_apply') widgets = { 'job_type':RadioSelect(), 'job_location':TextInput(attrs={'size':'70'}), 'job_description':Textarea(attrs={'cols':200, 'rows':10}), 'start_date':TextInput(attrs={ 'class': 'datepicker', 'data-date-format':

Django - How to redirect differently using LoginRequired and PermissionRequired?

好久不见. 提交于 2019-12-13 07:07:00
问题 I would like to create a Mixin which will: First - Check if a user is authenticated, if not, redirect to login url. If yes... Second - Check if user has a defined Profile (a user), if not, redirect to Profile creation, else, allow user to access the View. I was planning to do sometinhg like: class ProfileRequiredMixin(LoginRequiredMixin,PermissionRequiredMixin): #TODO check how multiple inheritance works treating conflicting methods '''This Mixin should first check if user is autheticated, if

MyModelForm' object has no attribute 'user using django

喜你入骨 提交于 2019-12-13 07:06:11
问题 i want to create i simple django image processing .first i have create correct a django auth and multi upload images in my app. now i want the user can select one self image from a list django form where i create and that image i get for my processing.i create something but not work. i take that error : 'MyModelForm' object has no attribute 'user' here the code : views.py @login_required(login_url="login/") def myview(request): Myf = MyModelForm(request.user,request.POST) return render

how to integrate recommender system(python file) to the django project.

一笑奈何 提交于 2019-12-13 06:59:40
问题 This is the python script made by my friend .How to integrate this file in my django project which contains all list of movies taken from the movierulz data set.Where should I integrate this code. import numpy as np import pandas as pd # set some print options np.set_printoptions(precision=4) np.set_printoptions(threshold=5) np.set_printoptions(suppress=True) pd.set_option('precision', 3, 'notebook_repr_html', True, ) # init random gen np.random.seed(2) #users_file = "/media/sourabhkondapaka

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