django-views

javascript function not getting called

穿精又带淫゛_ 提交于 2019-12-11 01:55:56
问题 In a Django template, I have a function function show_graph(i){ $("#"+i+"seegraph").click(function(){ $("#"+i+"graph").show(); var qaa = {{ question_ids }}; var qid = qaa[i-1]; jQuery.ajax({ url: "/canvas/recreatechart/", type: "get", data: {qid: qid }, success: function(response){ var resp = jQuery.parseJSON(response); alert("chart1"+i); show_graph("chart1"+i, resp['chart_type'], resp['series_names'], JSON.stringify(resp['data1']), resp['answer'], resp['stories1'], resp['colors'], resp[

Class Based View MySQL DateTimeField received a naive datetime

给你一囗甜甜゛ 提交于 2019-12-11 01:48:31
问题 I am very new to Django and at the end of my rope and really need some help. I do not know how to use a "class based view" and change the incoming datetimefield from my MySQL database into a Time Zone Supported entry that it seems to need. The database stores it in UTC and my system is on PST. I am getting this error: DateTimeField received a naive datetime (2012-09-01 00:00:00) while time zone support is active On my MonthArchiveView, DayArchiveView, DateDetailView 's only. For some reason

Adding a variable in Content disposition response file name-python/django

北战南征 提交于 2019-12-11 01:45:25
问题 I am looking to add a a variable into the file name section of my below python code so that the downloaded file's name will change based on a user's input upon download. So instead of "Data.xlsx" it would include my variable (based on user input) + "Data.xlsx". I saw a similar question but based in PHP and couldn't figure out how to adapt it to python. response = HttpResponse(content_type='application/vnd.ms-excel') response['Content-Disposition'] = 'attachment; filename= "Data.xlsx"' Thanks

Approach: python-pdfkit convert webpage(JS generated) into PDF

浪尽此生 提交于 2019-12-11 01:37:03
问题 views.py def download_as_pdf(request): # some stuff/function call to get updated(with data and JS) template and render it return render(request, temp) def download(request): import pdfkit pdfkit.from_url('/download/', 'out.pdf', options={'ignore-load-errors': None}) return HttpResponse('DONE') urls.py url(r'^download/', views.download_as_pdf, name="download_pdf") I want to print all content(some graphs (JS generated - flotcharts)) of /download/ url in pdf. If I put these two lines import

django - Get a set of objects from different models field names

寵の児 提交于 2019-12-11 01:29:51
问题 Please have a look at my models. class BackgroundImage(models.Model): user = models.ForeignKey(User) image = models.ImageField(upload_to=get_upload_file_name) caption = models.CharField(max_length=200) pub_date = models.DateTimeField(default=datetime.now) class ProfilePicture(models.Model): user = models.ForeignKey(User) image = models.ImageField(upload_to=get_upload_file_name) caption = models.CharField(max_length=200) pub_date = models.DateTimeField(default=datetime.now) class Album(models

Stopping multiple view calls generated via frenzied button clicks (Django app)

笑着哭i 提交于 2019-12-11 01:07:24
问题 I'm uploading an image file in a basic Django web app. There's an upload button in the html template wrapped around by a form tag. Once the upload button is pressed, the underlying view takes over and processes image upload. In the Chrome browser of my colleague's Macbook, pressing upload multiple times really quickly manages to call the underlying function multiples times too. I end up getting a plethora of copies of the image being uploaded. However, this isn't replicatable in my own

Django - Method Not Allowed on Function Based View (FBV)

跟風遠走 提交于 2019-12-11 00:56:11
问题 I am getting a 405 METHOD NOT ALLOWED response when I am trying to submit a POST request through an AJAX call: "POST /events/profile_update/ HTTP/1.1" 405 0 I'm trying to set this up with the most basic view: def profile_update(request): if request.method == "POST": name_form =forms.EventName(request.POST) if name_form.is_valid(): name = name_form.cleaned_data['name'] else: name_form = forms.EventName() return render(request, 'event_edit_profile.html', {"name": name}) my urls.py: urlpatterns

python - Django built in login view not redirecting to next

我的梦境 提交于 2019-12-11 00:55:31
问题 I am using django auth views for authentication but after successful login it should try to redirect the user to the next GET param but it is redirecting to LOGIN_REDIRECT_URL only! here is my url url(r'^login/$', auth_views.login, {'template_name': 'accounts/registered/login.html',}, name='login'), in my setting.py LOGIN_REDIRECT_URL = '/' when a unauthenticated user wants to visit dashboard it automatically redirected to login page with next param http://127.0.0.1:8000/accounts/login/?next=

Django: ORDER BY DESC on FloatField puts null values top?

喜欢而已 提交于 2019-12-10 23:49:50
问题 I'm surprised to find that an ORDER BY DESC query on a FloatField in Django returns null fields higher than fields with positive values. # In models.py class City(models.Model): name = models.CharField(max_length=30) country = models.ForeignKey(Country) value = models.FloatField(null=True, blank=True) # In views.py cities = City.objects.filter(country__id=country.id).order_by('-value') # In template.html {% for city in cities %}{{ city.name }}: {{ city.value }} --{% endfor %} I get back the

Displaying page content using django-page-cms

a 夏天 提交于 2019-12-10 23:33:11
问题 I would like to display some content located in my models in some of my template pages. I am using django-page cms In the documentation views are not used to display content. Instead ready made template tags are used. http://packages.python.org/django-page-cms/display-content.html I do not understand a word of this. Please Bear with me I am new. All I want to do is display some info located in my models inside a template this manner.. {% if latest_news_list %} {% for news in latest_news_list