Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Running ssh script Using Django and Apache server
I am running a remote script using ssh (putty.exe) with Django. I am able to kick off the script from Django front end when i run Devserver, but I am unable to kick off the script when I run the Django on apache mod_wsgi server. I am sure it is not kicking off the putty. But there is no error, on apache logs. So I am not sure how to debug this :( Is there any settings needs to be tweaked on Apache conf? it's been 24 hours I am struggling with this. Can anyone suggest what option I should be checking? I agree I do not have much input to provide here unless you want me to provide something specific. Thanks -
Spotify Client Credential Flow
Spotify recently updated their API conditions with the requirement that every request have authentication, which is fine, but when trying to set that up on the front-end I got the 'Access-Control-Allow-Origin' issue posted here: Access-Control-Allow-Origin denied spotify api because I was trying to do it through AJAX. My app does not require any personal spotify information, just pulling down preview URLs and track information from spotify, so I'd prefer if users didn't have to log in to use it. If I was going to implement Client Credential flow on the backend, where would I start? My app is a Django backend with JavaScript/React on the frontend. My main concern is that anywhere where I put the code to get myself a token has to come from the server side, but also be run every ~hour as the tokens expire. Any help is welcome, I can post code if necessary! -
how to implement a filter into a POST method in django?
I want to implement some filters into a POST method to filter a JSON but I do not know in which part of the code they should be. Does Python support POST methods to filter JSON objects or which trick can I use to implement the filters? JSON object [{ id: 1003384, user_id : 0001 CreatedOn: "2017-02-16 15:54:48", Problem: "AVAILABILILTY", VIP: "YES", Vendor_CODE: "XYZ12345", Week_id: "07", }, { id: 1003338, user_id: 0002 CreatedOn: "2017-02-15 13:49:16", Problem: "AVAILABILILTY", VIP: "NO", Vendor_CODE: "XYZ67890", Week_id: "09", }, { id: 1553338, user_id: 0002 CreatedOn: "2017-03-15 09:30:36", Problem: "AVAILABILILTY", VIP: "YES", Vendor_CODE: "ACE67890", Week_id: "13", }] Filters { "filter": { "filters": [ { "field": "CreatedOn", "operator": "gte", "value": "2017-02-12 00:00:00" }, { "field": "CreatedOn", "operator": "lte", "value": "2017-03-12 00:00:00" }, { "field": "VIP", "operator": "eq", "value": "YES" } ], "logic": "and" } } Python snippet code that displays the entire JSON (this snippet belongs to one of my views from my application) def get_data(request, *args, **kwargs): with urllib.request.urlopen("http://10.61.202.98:8081/T/ansdb/api/rows/dev/ect/tickets",timeout=15) as url: response_data = json.loads(url.read().decode()) #manual filter - retrieves the users from all the json user_id = [value['user_id'] for value in response_data] print(user_id) return JsonResponse(response_data, safe=False) -
Celery + Django -- Logging with RotationFileHandler, strange behavior
I have a Django project setup with Celery and a RotatingFileHandler setting like shown below: LOGGING = { 'version': 1, 'handlers': { 'console':{ 'class':'logging.StreamHandler', 'stream': sys.stdout, }, 'celery': { 'class': 'logging.handlers.RotatingFileHandler', 'filename': '/var/log/celery/celery.log', 'formatter': 'verbose', 'maxBytes': (1024 * 1024 * 10), # 10 mb 'backupCount': 10 }, }, 'formatters': { 'verbose': { 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' }, }, 'loggers': { 'sm9.views': { 'handlers':['console'], 'propagate': True, 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), }, 'sm9.helpers': { 'handlers':['console'], 'propagate': True, 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), }, 'sm9.soap': { 'handlers':['celery'], 'propagate': True, 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), }, 'sm9.tasks': { 'handlers':['celery'], 'propagate': True, 'level': os.getenv('CELERYD_LOG_LEVEL', 'INFO'), }, 'celery': { 'handlers': ['celery'], 'level': os.getenv('CELERYD_LOG_LEVEL', 'INFO'), 'propagate': True }, }, } When celery.log reaches 10mb the system is creating 3 more files: celery.log.1, celery.log.2 and celery.log.3. All three files are beeing populated simultaneously instead of reaching 10mb and opening a new file. Is this the expected behavior? Celery is running as a daemon with 3 threads. -
Why does cached_property always update the data?
There is a model, in its geoposition field, latitude and longitude are stored, as a string, in this form '27 .234234234,53.23423423434'. This field is provided by django-geoposition. Thanks to him it is very convenient to enter the address. I also need to store the real address. I do not know whether to do this correctly, but I decided to use geocoder, and store the result in cached_property class Address(models.Model): geoposition = GeopositionField(null=True) city = models.ForeignKey('cities_light.City', null=True) country = models.ForeignKey('cities_light.Country', null=True) entrance = models.CharField(null=True, max_length=4, blank=True) floor = models.CharField(null=True, max_length=4, blank=True) flat = models.CharField(null=True, max_length=4, blank=True) @cached_property def address(self): g = geocoder.yandex([ str(self.geoposition).split(',')[0], str(self.geoposition).split(',')[1] ], method='reverse', lang='ru-RU') return g.address def save(self, *args, **kwargs): if not self.address: self.address() super(Address, self).save(*args, **kwargs) def __str__(self): if self.address: return '%s' % str(self.address) return '%s' % str(self.pk) But the problem is that with every attempt to edit a model that is associated with the Address, I see that the property is being computed, and even in some cases I catch connection time out from external services. I can not understand the reason for this behavior. -
Logging request.META isn't working with Django Channels + Asgi_redis
I have a custom logging class and here is my logging settings: base.py LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(levelname)s|%(asctime)s|%(module)s|%(process)d|%(thread)d|%(message)s', 'datefmt' : "%d/%b/%Y %H:%M:%S" }, 'simple': { 'format': '%(levelname)s|%(message)s' }, }, 'handlers': { 'mail_admins': { 'level': 'WARNING', 'class': 'django.utils.log.AdminEmailHandler' }, 'console':{ 'level':'WARNING', 'class':'logging.StreamHandler', 'formatter': 'verbose' }, 'db':{ 'level': 'WARNING', 'class': 'apps.monitor.loggers.MyDbLogHandler', } }, 'loggers': { 'django': { 'handlers': ['db'], 'level': 'WARNING', } }, 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler', 'include_html': True, } } apps.monitor.loggers.py import logging import datetime import settings class MyDbLogHandler(logging.Handler): # Inherit from logging.Handler def __init__(self): # run the regular Handler __init__ logging.Handler.__init__(self) def emit(self, record): # instantiate the model try: #NOTE: need to import this here otherwise it causes a circular reference and doesn't work # i.e. settings imports loggers imports models imports settings... from apps.monitor.models import SystemErrorLog ip = record.request.META['REMOTE_ADDR'] # during development if 'HTTP_X_FORWARDED_FOR' in record.request.META: # load balancer ip = record.request.META['HTTP_X_FORWARDED_FOR'] logEntry = SystemErrorLog( level=record.levelname, url=record.args[0], get=record.request.META['QUERY_STRING'], agent=record.request.META['HTTP_USER_AGENT'], status=getattr(record, 'status_code', None), ip=ip, module=record.module, process=record.process, thread=record.thread, message=record.message, timestamp=datetime.datetime.now(), serialized=record.__dict__ ) logEntry.save() except: pass return It was working fine, but now I've installed Django Channels and my record.request.META doesn't exists anymore. This is my record: { 'name':'django.request', 'msg':'Not Found: %s', … -
Django Model With ManyToMany Not Saving
I have a list of menus--with items listed on the menu. Here is my model: class Menu(models.Model): season = models.CharField(max_length=20) items = models.ManyToManyField('Item', related_name='items') created_date = models.DateTimeField(default=timezone.now) expiration_date = models.DateTimeField(blank=True, null=True) def __str__(self): return self.season class Item(models.Model): name = models.CharField(max_length=200) description = models.TextField() chef = models.ForeignKey('auth.User') created_date = models.DateTimeField( default=timezone.now) standard = models.BooleanField(default=False) ingredients = models.ManyToManyField( 'Ingredient', related_name='ingredients' ) def __str__(self): return self.name For some reason--in the admin--i can edit the menu and it will save the items properly--but if i do so in the edit view for the menu it does not save the items (it does however save the season and expiration_date). That's why i thought maybe it was the ManyToMany relationship? Any ideas? Here is my edit view: def edit_menu(request, pk): menu = get_object_or_404(Menu, pk=pk) items = Item.objects.all() if request.method == "POST": menu.season = request.POST.get('season', '') menu.expiration_date = datetime.strptime(request.POST.get('expiration_date', ''), '%m/%d/%Y') menu.items = request.POST.get('items', '') menu.save() return redirect('menu_detail', pk=menu.pk) return render(request, 'menu/change_menu.html', { 'menu': menu, 'items': items, }) and menu detail page {% extends "layout.html" %} {% block content %} <div class="content container"> <div class="row"> <div class="col-md-8"> <div class="post"> <h1> {% if user.is_authenticated %} <a class="btn btn-default" href="{% url 'menu_edit' pk=menu.pk %}"><span class="glyphicon glyphicon-pencil"></span></a> {% endif %} … -
Django- Multiple languages on the same site
My issue has to do with a Django site running using one language, and using specific languages for specific apps My example is: I want to run a 'pt-pt' (Portuguese- Portugal) Django site. In it, I'm using a 3rd party App that has pt-BR (Portuguese- Brazil) as an available language, but no pt-pt translation. Lacking, pt-pt, pt-BR would be better than English. I can set the language as: #settings.py... LANGUAGE_CODE = 'pt-pt' But then the site Admin uses pt-pt and the App uses English (undesirable). If I set it to pt-BR I'll get pt-BR on the site (undesirable) and pt-BR on the App. So I read Django's Docs again and tried the Languages setting #settings.py... LANGUAGE_CODE = 'pt' from django.utils.translation import ugettext_lazy as _ LANGUAGES = ( ('pt', _('Portuguese')), ('pt-br', _('Brazilian Portuguese')), ) to no avail (nothing changed). Is there a way to do this? -
How to update an object in Django rest framework
I have a custom user model, and have its model seriazer to with. Its modelviewset also works in displaying the user list. class UserSerializer(serializers.ModelSerializer): password1 = serializers.CharField(write_only=True, style={'input_type': 'password'}) password2 = serializers.CharField(write_only=True, style={'input_type': 'password'}) mobile = serializers.IntegerField() class Meta: model = User fields = ('id', 'first_name', 'last_name', 'email', 'mobile', 'password1', 'password2') def validate(self, data): if data['password1'] != data['password2']: raise serializers.ValidationError({'password1': 'Both password must be equal.'}) return data def create(self, validated_data): if self.is_valid(True): return User.objects.create_user( validated_data.get('email'), validated_data.get('first_name'), validated_data.get('last_name'), validated_data.get('mobile'), validated_data.get('password1'), ) class UserViewSet(viewsets.ModelViewSet): queryset = User.objects.all() serializer_class = UserSerializer However, I am trying to update a User object by posting the model's fields and its value in json key value pair format in PUT http method. { "first_name": "Some" "last_person": "name" "mobile": "0123456789" } But this gives me a 400 bad request error: { "password1": [ "This field is required." ], "password2": [ "This field is required." ], "email": [ "This field is required." ] } How can I update an object with only the partial model fields? -
Django NOT NULL constraint failed: shop_product.user_id
I am new to Django and I am trying to practice with some project but I am stock with this problem NOT NULL constraint failed: shop_product.user_id Here is my models.py from django.db import models from django.conf import settings from django.core.urlresolvers import reverse class Category(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='category_created') name = models.CharField(max_length=200, db_index=True) slug = models.SlugField(max_length=200, db_index=True, unique=True) class Meta: ordering = ('name',) verbose_name = 'category' verbose_name_plural = 'categories' def __str__(self): return self.name class Product(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='product_created') category = models.ForeignKey(Category, related_name='products') name = models.CharField(max_length=200, db_index=True) slug = models.SlugField(max_length=200, db_index=True) image = models.ImageField(upload_to='products/%Y/%m/%d', blank=True) description = models.TextField(blank=True) price = models.DecimalField(max_digits=10, decimal_places=2) stock = models.PositiveIntegerField() available = models.BooleanField(default=True) negiotiable = models.BooleanField(default=True) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) users_like = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='product_liked', blank=True) class Meta: ordering = ('name',) index_together = (('id', 'slug'),) def __str__(self): return self.name def get_absolute_url(self): return reverse('products_detail', args=[self.slug]) Here is my views.py but am not sure if there is problem with my views and I think the problem will have to be with my models from django.views.generic import * from django.core.urlresolvers import reverse_lazy from .models import Category, Product class CategoryList(ListView): model = Category class CategoryDetail(DetailView): model = Category class ProductList(ListView): model = Product class ProductDetail(DetailView): model = Product class … -
Login Application in Django with my own Database tables
I am new to django, I just started developing a basic college portal application. I want to create the login form for students based on their enrollment number and password, but all i can find in the documentation is the auth package and logging in and out using authentication filters. i have a login table (enrollment_number, password). how can i use it in django to authenticate student login instead of the default authentication system provided? -
Django: dynamic table creation programmatically
I want to create table dynamically for each user when he/she will register to my site in Django with sqlite3. I have searched for various method and I found some methods also but unfortunately I am not satisfied with these methods or I have problems with these methods. These are the method I found: using South: problem - Deprecated for Django > 1.6 using Syncdb: problem - sql_model_create(model, style) method is deprecated. No doc found for a new version of Django 1.11. Performing raw SQL queries: problem - SQL Injection/other security issue or I don't want to use. Is there any other method to create table dynamically/programmatically in Django 1.10 or 1.11? Please give your answer with any example(if possible). -
ImportError: No module named urls
I have a django rest project which is built on Django1.7. I need to run it on Django 1.11. When i run python manage.py migrate The error is: ImportError: No module named urls on url.py line url(r'^docs/', include('rest_framework_swagger.urls')), I have already made modifications in url.py file to avoid patterns. The url.py file look like from django.conf.urls import include,url from django.conf import settings from django.conf.urls.static import static from django.views.generic.base import TemplateView from django.contrib import admin admin.autodiscover() urlpatterns = [ url(r'^grappelli/', include('grappelli.urls')), url(r'^docs/', include('rest_framework_swagger.urls')), url(r'^admin/', include(admin.site.urls)), url(r'', include('gcm.urls')), url(r'^', include('apps.account.urls')), url(r'^', include('apps.vegetables.urls')), url(r'^', include('apps.orders.urls')), url(r'^', include('apps.listings.urls')), url(r'^', include('apps.rating.urls')), url(r'^', include('apps.faq.urls')), url(r'^thank-you/$', TemplateView.as_view(template_name="thankyou.html"), name="thankyou"), url(r'^/error/$', TemplateView.as_view(template_name="error.html"), name="error"), url(r'^$', TemplateView.as_view(template_name="index.html"), name="home"), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += [ '', (r'^static/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.STATIC_ROOT})] How could i run it? -
Custom Exception Handler not called in Rest Framework for validator
I setup according to last docs a custom exception handler: REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.SessionAuthentication', 'rest_framework.authentication.BasicAuthentication', 'code.core.authentication.CustomJSONWebTokenAuthentication', ), 'EXCEPTION_HANDLER': 'goldi.core.utils.custom_exception_handle', 'DEFAULT_PAGINATION_CLASS': 'code.core.utils.CustomLimitOffsetPagination', 'PAGE_SIZE': 10 } from rest_framework.views import exception_handler def custom_exception_handler(exc): # Call REST framework's default exception handler first, # to get the standard error response. import pdb; pdb.set_trace() <-- NEVER GET THERE When call http POST :8000/api/v1/company/ I get: HTTP/1.0 400 Bad Request Allow: GET, POST, OPTIONS Server: WSGIServer/0.1 Python/2.7.13 { "name": [ "This field is required." ] } But I need to intercept that exception and add more data. -
Heroku - Python / Django R14 - Memory quota exceeded
I am unable to delete model instances in the Django admin. When I try I get an application error with the following logs: 2017-06-01T16:49:52.582763+00:00 app[web.1]: [2017-06-01 16:49:52 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:27) 2017-06-01T16:49:53.966027+00:00 app[web.1]: [2017-06-01 16:49:53 +0000] [54] [INFO] Booting worker with pid: 54 2017-06-01T16:50:12.048171+00:00 heroku[web.1]: Process running mem=642M(125.4%) 2017-06-01T16:50:12.048339+00:00 heroku[web.1]: Error R14 (Memory quota exceeded) 2017-06-01T16:50:22.371199+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/admin/auth/user/" request_id=e850ec27-3452-4e05-9077-00107a6dbd08 fwd="69.250.203.83" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=http 2017-06-01T16:50:23.409859+00:00 app[web.1]: [2017-06-01 16:50:23 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:45) 2017-06-01T16:50:23.676154+00:00 app[web.1]: [2017-06-01 12:50:23 +0000] [45] [INFO] Worker exiting (pid: 45) 2017-06-01T16:50:24.927345+00:00 app[web.1]: [2017-06-01 16:50:24 +0000] [63] [INFO] Booting worker with pid: 63 This is my procfile: web: gunicorn djangoall.wsgi worker: celery -A djangoall worker --autoscale=10,3 beat: celery -A djangoall beat -S django Performing this action works fine in my local environment. The Heroku documentation references memory errors are language specific and does not include a Python guide. I have looked at the number of SO questions but did not have success when I lowered workers by one (by changing --autoscale=10,3 to --autoscale=10,2) per this answer I am getting Error R14 (Memory quota exceeded) in heroku with a Django app. -
What is the expected return signature for django.contrib.auth.models.PermissionsMixin.get_all_permissions?
I know that django.contrib.auth.models.PermissionsMixin.get_all_permissions is supposed to return a Set[str], but specifically, what is the make-up of the strings? I see many examples in the form of 'APP_NAME.PERM_NAME' where APP_NAME is the name of the Django app, and PERM_NAME is the codename of the permission which is defined in the app model's Meta class's permissions attribute. The get_all_permissions method has an optional obj parameter. When I pass in a model instance I get a Set[str] with a string signature of PERM_NAME, omitting the APP_NAME completely when using the django-guardian package. I understand that in this case the APP_NAME may be redundant except for one case: multiple inheritance. A Django model can have multiple inheritance, and the multiple inheritance can be across apps. So if this is the case, is django-guardian doing it wrong? I cannot find any other examples of a Django application auth backend that uses object permissions. -
Django - using instance.id while uploading image
I was referring to this youtube video, to understand how to upload image using ImageField. He has explained how to use the instance.id while saving the image. I tried it, but instance.id is returning None. Whereas for him it worked perfectly. The following is the code: #models.py import os def get_image_path(instance, filename): return os.path.join(str(instance.id), filename) class AdProfile(models.Model): name = models.CharField(max_length=100) profile_image = ImageField(upload_to=get_image_path, blank=True, null=True) Whenever the file is saved, its saving as None/filename. Even this link informs the same. I am using Django 10.5 and MySQL database. What might be the problem. Kindly help. -
How can I count the number of times an item appears in a JSON object? Django
I developed the following code to extract data from a web API and I am trying to manipulate it based on the following condition: Count the number of times that users appear between dates initial date which is current time - 6 days and final date is current time. The JSON object that I receive has the following structure: [{ id: 1003384, user_id : 0001 CreatedOn: "2017-02-16 15:54:48", Problem: "AVAILABILILTY", VIP: "YES", Vendor_CODE: "XYZ12345", Week_id: "07", }, { id: 1003338, user_id: 0002 CreatedOn: "2017-02-15 13:49:16", Problem: "AVAILABILILTY", VIP: "NO", Vendor_CODE: "XYZ67890", Week_id: "09", }, { id: 1553338, user_id: 0002 CreatedOn: "2017-03-15 09:30:36", Problem: "AVAILABILILTY", VIP: "YES", Vendor_CODE: "ACE67890", Week_id: "13", }] Now, when I execute the following code I cannot count the number of times the users appears between given two dates because I get the error keys should be integers not strings and I do not know where should I implement the initial and final dates. from datetime import datetime, timedelta from rest_framework.response import Response import json, urllib.request from collections import Counter #Request a response to the Web API def get_data(request, *args, **kwargs): # YYYY-MM-DD start_date = datetime.now() - timedelta(days=7) end_date = datetime.now() - timedelta(days=1) with urllib.request.urlopen("http://10.61.202.98:8081/T/ansdb/api/rows/triage/ect/tickets",timeout=15) as url: … -
Django CMS not working with uWSGI
I have website developed in Django CMS. When running it with the manage.py runserver it works just fine but when I try to run it with nginx and uwsgi I get the following error: view must be a callable or a list/tuple in the case of include(). I think it might the problem might be that I run the django cms in a virtualenv. I used the same conf files for another django project but it wasn't inside an virtualenv I start the uwsgi inside my virtualenv. My wsgi.ini [uwsgi] chdir = /var/www/user.name/mysite module = mysite.wsgi #home = /var/www/user master = true processes = 10 socket = /var/www/user/mysite/mysite.sock chmod-socket = 666 vcuum = true My nginx conf upstream django { server unix:///var/www/user/mysite/mysite.sock; } server{ # listen on port listen 80 default_server; listen [::]:80 default_server; server_name example.name www.example.name; return 301 https://$server_name$request_uri; } server{ #Default server? listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; server_name example.name www.example.name; charset utf-8; client_max_body_size 75M; ssl_certificate /etc/letsencrypt/live/user/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/user/privkey.pem; include snippets/ssl-params.conf; location ^~ /.well-known{ allow all; alias /var/www/user/.well-known; } location /static { alias /var/www/user/mysite/mysite/static; } location / { uwsgi_pass django; include /var/www/user/mysite/uwsgi_params; } } -
What the right way to localize the price in the Django-shop?
I know easy way, make a few different fields for needed currencies, but that's not only ugly, but the currencies will be hardcoded. It seems to me be more elegant through django-parler, but I do not quite understand how to do it. -
manage.py runserver 0.0.0.0:8000 ImportError No module named DBCONN
I am running the manage.py runserver and getting an import error for "dbconn" The file exists in the django project directory. Here is the directory listing of my django project. Also below this I have included my traceback. If anyone has any ideas, I am learning django on the fly. -rw-rw-r--. 1 cchadwick cchadwick 1230 Jun 1 12:30 chartcall.py -rw-rw-r--. 1 cchadwick cchadwick 1651 Jun 1 12:24 dbconn.py -rw-rw-r--. 1 cchadwick cchadwick 0 May 26 14:43 __init__.py drwxrwxr-x. 2 cchadwick cchadwick 240 Jun 1 12:30 __pycache__ -rw-rw-r--. 1 cchadwick cchadwick 3569 Jun 1 11:58 settings.py -rw-rw-r--. 1 cchadwick cchadwick 959 May 30 14:10 urls.py -rw-rw-r--. 1 cchadwick cchadwick 181 May 31 15:04 views.py -rw-rw-r--. 1 cchadwick cchadwick 396 May 26 14:43 wsgi.py (dbenv) [cchadwick@opendev-cutco-com dashproj1]$ python manage.py runserver 0.0.0.0:8000 Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f4d001ce488> Traceback (most recent call last): File "/home/cchadwick/dbenv/lib/python3.4/site-packages/django/utils /autoreload.py", line 227, in wrapper fn(*args, **kwargs) File "/home/cchadwick/dbenv/lib/python3.4/site-packages/django /core/management/commands/runserver.py", line 117, in inner_run autoreload.raise_last_exception() File "/home/cchadwick/dbenv/lib/python3.4/site-packages/django/utils/autoreload.py", line 250, in raise_last_exception six.reraise(*_exception) File "/home/cchadwick/dbenv/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise raise value.with_traceback(tb) File "/home/cchadwick/dbenv/lib/python3.4/site-packages/django/utils/autoreload.py", line 227, in wrapper fn(*args, **kwargs) File "/home/cchadwick/dbenv/lib/python3.4/site-packages/django/__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/home/cchadwick/dbenv/lib/python3.4/site-packages/django/apps/registry.py", line 85, in populate app_config = AppConfig.create(entry) … -
What technologies should I use for a local web application that displays information extracted from Splunk database
My goal is to create a simple dashboard which reports specific data to the user. This web application will be hosted on a local machine. The information that this application reports to the user is extracted from a Splunk database. I have been suggested Django (Python) web-framework for development. Will a Django based web application be able and is the right choice to interact with Splunk? I am confused because I came across "Splunk Web Framework" as well. Is this what I am looking for or I should just use Splunk SDK in my Django-python backend. I was also suggested to develop a REST web service. But I personally believe that this would be an overkill for a simple locally hosted web application that just searches the Splunk database and displays the report via GUI. To give an idea: I am supposed to develop this application within 4-5 weeks. I am good at programming with decent experience, but this is the first time I am developing a web application from front-end to back-end. -
The best solution to retrieve the most relevant outputs to the each user (in Django or any Backend)?
I'm looking for the best solution to retrieve the most relevant outputs to the each user. I simplified my models as UserProfile and Groups like below -Model Name: UserProfile styles: ['a', 'b', 'f', 'r'] <- ('styles' are field name) -Group 1 styles: ['a', 'f'] -Group 2 ['g', 'a', 'h'] ... -Group 1,000,000 styles: ['s', 'w', 'x'] (Let's say we have millions of Groups) I want to sort and retrieve groups based on the user's styles. So in this case, 'Group 1' scores 2 because of the styles 'a', 'f', and 'Group 2' scores 1 because of the style 'a'. We can't store the scores in our main database because each user has different styles. My Approach 1: rank all database every time when user requests (I wrote a code conceptually) views.py for group in Group.objects.all(): # store the score to the new field of the group group.style_count = group.styles.join_count(user.styles) list_view_output = Group.objects.order_by(style_count) Approach 2: Store the rank on database Execute the query and store the outputs (with rank of course and user id) in Redis in-memory cache database. And retrieve results when specific user wants to Problems in mind: The query seems quite expensive. O(n) for iterating * O( min( … -
Using a datepicker with django-bootstrap3
I am trying to render a datepicker in my django application. The datepicker I am currently using is django-datetime-widget. However, when I try to render it in my form I am getting the following error: Uncaught TypeError: $(...).datetimepicker is not a function I think the problem is coming from the fact that I am using django-bootstrap3. As I am extended the template that is provided by that module. All the bootstrap scripts are included in the <body> of the templates. I have overridden this by using: BOOTSTRAP3 = { 'javascript_in_head': True, } So the bootstrap js appears in the header rather than the body. I'm not really sure how to get the datepicker to render. Any help with this would be much appreciated. Thanks in advance. -
Django - Heroku - Serving dynamic large file timing out
I have one function view that creates a report using xlsxwriter, it is created on the fly using a StringIO as buffer and finally sending through HttpResponse. It works well using Local Server. The problem is that on Heroku, after some seconds (documentation mention 30 seconds timeout and not modifiable) the server hangs out and reboot the web process, giving error as a response. What is the best way to...?: create an xmlx file on the fly (dynamically) in memory serve the entire file to the client. prevent server to hang out because of the long process running This is a piece of the code I am using def reporte_usuarios(request): from xlsxwriter.workbook import Workbook try: import cStringIO as StringIO except ImportError: import StringIO # create a workbook in memory output = StringIO.StringIO() workbook = Workbook(output) bold = workbook.add_format({'bold': True}) # get the data from django.db.models import Count usuarios = User.objects.filter(....... # all filter stuff for usr in usuarios: if usr.activos > 0: # create a workbook sheet every User registered ws = workbook.add_worksheet(u'%s' % usr.username) # some relevant user data ws.write(1, 1, u'USUARIO: %s' % usr.username) ... # get rows for user log = LogActivos.objects.filter(usuario=usr).select_related('activo__unidad__id', 'activo__unidad__nombre', 'activo__nombre') # write headers …