django-views

How to make an external database query iterable?

回眸只為那壹抹淺笑 提交于 2019-12-14 03:45:55
问题 I have the following code: settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'tectcom', 'USER': 'test', 'PASSWORD': '***146***', 'HOST': '', 'PORT': '', }, 'cdr': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'ast', 'USER': '123', 'PASSWORD': '654', 'HOST': '', 'PORT': '', } views.py def cdr_user(request): cursor = connections['cdr'].cursor() calls = cursor.execute('SELECT * FROM cdr') return render_to_response("cdr_user.html", {'result':calls }, context

Django test project TemplateDoesNotExist at /

£可爱£侵袭症+ 提交于 2019-12-14 03:17:39
问题 I know this question has been asked many times but even after resolving all the things I am still getting this error. My setup is as follow - settings.py """ Django settings for my_notebook project. Generated by 'django-admin startproject' using Django 1.8.3. For more information on this file, see https://docs.djangoproject.com/en/1.8/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """ # Build paths inside the project

Send email using environment variables via Django for security

时光总嘲笑我的痴心妄想 提交于 2019-12-14 03:08:27
问题 I can send emails using environment variables in my settings.py, however how do I input these variables in views.py? When put the actual email in str--it works; but for extra security, I written it as env. variable and gave me an error: SMTPRecipientsRefused. Also, how do I get it to show the sender's email. It shows in the console, but not when I receive the email. I am trying to get different users to send to one email recipient as contact form. settings.py: SECRET_KEY = os.environ.get(

parsererror and Unexpected token < in JSON at position in ajax and django?

三世轮回 提交于 2019-12-14 03:05:06
问题 please look into below code AJAX FUNCTION <script> $(document).ready(function() { $("#id_module").on('change', function(){ var mod1 = $(this).val(); alert(mod1); $.ajax({ url: 'submodule/'+ mod1, type:'GET', dataType:'json', success: function(response){ alert(JSON.stringify(response)); submod=response['submod']; alert(submod); $('#submodule').empty(); $("#submodule").prepend($('<option>', { value: '', text: '-- Select Sub Module Type --' })); $.each(submod, function(ind){ $("#submodule")

Save method of Django model's instance does not update fields [closed]

本秂侑毒 提交于 2019-12-14 02:17:35
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I have a problem with the save of a Django models' instance. In my models.py, I have : class Thing(models.Model): title = models.CharField(null=True,max_length=128) text = models.TextField(null=True) kind = models.CharField(max_length=32,null=False) date = models.DateField(auto_now_add=True, blank=True) And,

Calling a templatetag from a view — CSRF not gtting populated

筅森魡賤 提交于 2019-12-13 21:54:49
问题 I am using inclusion_tags to generate portions of my pages that repeat in many different places across my site. templatetags/tags.py @register.inclusion_tag('chunk_template.html') def output_chunk(object, edit): ... # Lots of set up work here that I don't want to duplicate in the view return { ... } Upon AJAX submit of a form on the page, I need to refresh the very same HTML outputted by output_chunk(). To avoid completely rewriting output_chunk() in a view, I did the following as recommended

Object html representation in Django

点点圈 提交于 2019-12-13 21:19:16
问题 I have written a python app which as a result creates a list of Result objects. I've written a method which makes a html representation of the object Result, showing its main attributes. class Result(): def to_html(self): num_of_exp = "Number of exponentials: %s"% self.number_of_exponentials function = "Function: %s"% self.function par_of_exp = "Parameters of exponentials: <br /> %s "% pprint.pformat(self.parameters_of_exponentials) chunk = "Chunk: <br /> %s"% pprint.pformat(self.chunk)

compare the date of all DateFields in a model to the current date

瘦欲@ 提交于 2019-12-13 21:12:15
问题 if i have in my model class MyModel(models.model): field1 = models.ForignKey(AnotherModel) field2 = models.DateField(blank=True, null=True) field3 = models.DateField(blank=True, null=True) field4 = models.DateField(blank=True, null=True) field5 = models.DateField(blank=True, null=True) ... field10 = models.DateField(blank=True, null=True) i want to test for each field if the day is in the past, so i can use in my template something like that: {% for field in context.datetime_fields %} {% if

form_valid method in django-extra-views. In reality form(s)_valid

独自空忆成欢 提交于 2019-12-13 20:28:23
问题 I am trying to use Django Extra Views pack to create new entry based on model + inline formset + extra information from the USER model. I know how to do it via function based views but now trying to decrease amount of the code: I have 2 models + user model: Model1: # primary model author = models.ForeignKey("ExtraUser", ) +some fileds Model2 # secondary model photo = models.ForeignKey("Model1", ) + some fields # user model Model ExtraUser(AbstractBaseUser) + some fileds I use following VIEW

How to get Task ID in celery django from the currently running Shared Task itself?

偶尔善良 提交于 2019-12-13 20:10:04
问题 In my views.py I am using celery to run a shared task present in tasks.py . Here is how I call from views.py task = task_addnums.delay() task_id = task.id tasks.py looks as from celery import shared_task from celery.result import AsyncResult @shared_task def task_addnums(): # print self.request.id # do something return True Now, as we can see we already have task_id from task.id in views.py . But, Let's say If I want to fetch task id from the shared_task itself how can I ? The goal is to get