django-views

How to enroll custom user as students in django

吃可爱长大的小学妹 提交于 2019-12-11 14:24:15
问题 I have django course model and custom user as students I added some course for logged student, Now i need to show the profile of user or student and his course in student_profile.html here is my model for course class Course(models.Model): students = models.ManyToManyField('Profile', blank=True) Course_Name = models.CharField(max_length=200) Duration_Time = models.CharField(max_length=50) Course_Fee = models.IntegerField() Discount_Fee = models.IntegerField() Course_Image = models.FileField()

NameError name 'Views' is not defined

折月煮酒 提交于 2019-12-11 13:38:23
问题 from django.conf.urls import url, patterns, include from django.contrib import admin from django.views.generic import TemplateView from collection import * #from collection.views import index,thing_detail,edit_thing urlpatterns = [ url(r'^$', views.index, name='home'), url(r'^about/$',TemplateView.as_view(template_name='about.html'),name='about'), url(r'^contact/$',TemplateView.as_view(template_name='contact.html'),name='contact'), url(r'^things/(?P<slug>[-\w]+)/$', 'views.thing_detail' ,name

How to redirect from Django views to a specific view of angular JS

只愿长相守 提交于 2019-12-11 13:19:50
问题 I am working on something which has combo of Django and Angular JS. As the word goes, it little tricky to mix these two. I have everything working fine and so i decided to apply User Authentication. I have applied @login_required which redirects user to login page if not logged in , before checking out. urls.py url(r'^checkout/$','ecommerce.views.checkout'), views.py @login_required def checkout(request): return render_to_response('#checkout0',content_type="text") app.js .when('/checkout0', {

Django - Prepare objects from a view for Current User

一笑奈何 提交于 2019-12-11 12:46:15
问题 Consider this model class Exercise(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class Score(models.Model): """Scores of users by exercise""" exo = models.ForeignKey(Exercise) user = models.ForeignKey(User) score = models.IntegerField() class Meta: unique_together = (('exo', 'user',),) I have a template which displays the Exercise s. <ul> {% for exo in exos %} <li>{{ exo }}</li> {% endfor %} </ul> Here is the view def view_exos(request): ""

passing values between views django

社会主义新天地 提交于 2019-12-11 12:03:10
问题 I want to pass value from one form to another but i am not using form wizard. my views: def main_page(request): #if request.method == 'POST': #form = jobpostForm_first() # if request.method == 'POST': if request.method == 'POST': #if '_Submit'in request.POST: #if (form.data['post_type']=='Job'): form = jobpostForm_first(request.POST) if (form.data['post_type']=='Job'): #if form.is_valid(): #form.save() return render_to_response('portal/job_post.html',{'form':form},context_instance

Django - UpdateView form does not save

断了今生、忘了曾经 提交于 2019-12-11 11:56:58
问题 My code for using forms inside CBV ( UpdateView ) won't save to DB when clicking Submit button. I don't see what's wrong. views.py class BHA_UpdateView(UpdateView): template_name = 'bha_test.html' context_object_name = 'bha' model = BHA_List success_url = reverse_lazy('well_list') pk_url_kwarg = 'pk_alt' form_class = BHA_overall_Form def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) api = get_well_api(self.request) context['single_well_bha_list'] = BHA_List

How to re-input variable to session after update password in django ?

岁酱吖の 提交于 2019-12-11 11:27:43
问题 i'm new in django and i'm trying to create an application that Admin have CRUD function. My problem is when admin updated other user, it function work properly. But, when admin update him/her self, update function can not run properly. I know the problem located when i change the user's password, their session is reset. Django takes care of re-injecting the session hash so values stored in the session will be gone. So I want to ask, how to enter the value after i do an update my password to

Axios unable to get JSON from Django view

。_饼干妹妹 提交于 2019-12-11 10:47:55
问题 I want to implement a front-end and back-end data interaction with axios and django view. Now I have succeed in posting data to django view with code below. axios.post("{% url 'main:getCommodityInfo'%}", param, {headers:{'X-CSRFToken': this.getCookie('csrftoken')}}) .then(response=>{ console.log(response); alert("response has been caught"); }) .catch(error=>{ console.log(error); alert("connection has error") }) But when I want to return json from view to axios: def getCommodityInfo(request):

“if request.method == 'POST':” == False, but “if request.POST” == True. Why?- Django

若如初见. 提交于 2019-12-11 10:41:36
问题 When I use the following code, the first if statement always returns a False. But if I change it to request.POST it will return a True. Does anyone know why? Has anyone else experienced this? I'm sending it data using a basic form with method="post". def add_new_user(request): context = RequestContext(request) if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): form.save(commit=True) return index_input(request) else: print form.errors else: form = NewUserForm()

Customizing django form based on currently logged in user

冷暖自知 提交于 2019-12-11 10:27:59
问题 This is a part of my forms.py class SubjectForm(forms.ModelForm): title=forms.CharField(label='',widget=forms.TextInput(attrs={'maxlength':150, 'placeholder':'Write here. . .'})) body=forms.CharField(label='', widget=forms.Textarea(attrs={'placeholder':'Extend here. . .'})) board=forms.ModelChoiceField(label='',queryset=Board.objects.all(), empty_label='Select Board') class Meta: model = Subject fields = ('title','body','board') Right now it's rendering all Board objects in board form field