Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Is there a way to hook a script into Django's test server, so that it executes on each reload?
I have certain files that I want to be static on production but want to be able to write dynamically during development. So I would like to be able to execute a script to accomplish this each time the test server reloads, so that changes I have made will be taken into account, and the file gets updated. Is there any way to hook into the autoreloader to do this, or is this something I would need to do manually? -
Override Django Render Methods
With the following renderer... from django.shortcuts import render ... return render(request, 'template.html', {'context':context,}) Is it possible to override the render classe's methods so that I can in certain circumstances interpret template tags myself for example if I find a tag consisting of a certain format such as... {% url 'website' page.slug %} I could point it to... /theme/theme-1/page.html or /theme/theme-2/page.html depending on extranious settings. -
Deploying project in Docker with Angular 4, Django and postgresql
I am trying to deploy on Heroku my project in Docker with Angular 4 frontend with Django backend and postgresql database. At this moment my files looks as shown below. I am note sure if this is done properly? I have pushed it using heroku container:push web --app myproject but it doesn't work. My logs: 2017-07-07T10:27:30.448951+00:00 heroku[web.1]: State changed from crashed to starting 2017-07-07T10:27:30.436282+00:00 heroku[web.1]: Process exited with status 0 2017-07-07T10:27:50.846928+00:00 heroku[web.1]: Starting process with command `python3` 2017-07-07T10:27:53.350381+00:00 heroku[web.1]: Process exited with status 0 2017-07-07T10:27:53.365013+00:00 heroku[web.1]: State changed from starting to crashed 2017-07-07T10:27:53.876208+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=e1f8edfc-7dc4-4bd3-91be-0a853e948452 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:28:43.444860+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=361846d1-41cd-403a-989f-4c29a0d1179e fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:28:43.984059+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host= myproject.herokuapp.com request_id=658795c8-0ba7-4988-9d39-34601b1334c7 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:28:44.673789+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=63fbabdc-7ba7-4997-81be-c601a0d83368 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:29:53.091547+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=a3943544-9dc4-44f0-b788-a462cdfba7d0 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:29:54.419623+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=eb5191e2-21d9-410c-823e-c57bb0fb7fa4 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https … -
how to make a view for django 1.8 and mongodb (mongoengine)
i am making an application using django 1.8 and mongoengine.i want that my application display specifically one column(battery_status) which is in collection (location) of monogodb database(pom). i am following these step 1. setting.py 2. model.py but now i am stuck with view. what should i place in view ? Can someone plz suggest how should be my application view.py file. setting.py - DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'admin_db', 'USER': 'root', 'PASSWORD': 'root', 'HOST': 'localhost', }, 'pom' : { 'ENGINE' : 'django.db.backends.dummy', 'NAME' : 'pom', }, } from mongoengine import connect connect( db='pom', username='admin', password='root', host='mongodb://admin:root@localhost' ) model.py - class location(Document): user_id = IntField(blank=True, null=True) name = StringField(max_length=100) loc_lon = FloatField(blank=True, null=True) timestamp = DateTimeField(blank=True, null=True) activity = StringField() lot_lat = FloatField(blank=True, null=True) batter_status = StringField() address = StringField() date_created = DateTimeField(auto_now_add=True) template file - {% extends 'includes/base.html' %} {% load staticfiles %} {% load filters %} {% block content %} <link rel="stylesheet" href="{% static 'css/jquery-ui.css' %}"> <script type="text/javascript"> </script> <style type="text/css"> tfoot { display: table-header-group; vertical-align: middle; border-color: inherit; } .rmove-brdr{box-shadow:none !important;border:0 !important;} </style> <!-- Content Wrapper. Contains page content --> <!-- Content Header (Page header) --> <section class="content-header"> <h1 class="pull-left"> Travelling Time </h1> <div>&nbsp;</div> <h3 class="box-title"> … -
jQuery and jinja2 .data("") returning undefined
the no of items are displayed along with an edit button with each item on clicking edit button the data of button is retrieved in jQuery function but I am getting undefined not the data-id <div> {% for stock in part_temp.part_stock_set.all %} {% with id="list"|concatenate:stock.id btn_id="btn"|concatenate:stock.id %} <div id="{{ id }}"> {{ stock.entry_date}} {{ stock.supplier }} {{ stock.amount }} {{ stock.remaining }} <button id="{{ btn_id }}" type="submit" data-id="{{stock.id}}" onclick="display_popup()" style="position: absolute; right:0;" >edit</button> <hr> </div> <br> {% endwith %} {% endfor %} </div> instead of {{stock.id}} I also tried passing other string but still got undefined <script type="text/javascript"> function display_popup() { var name = $(this).data("id"); window.alert(name); } </script> instead of .data() also tried other like .text() .Val but got nothing -
Django Reportlab generates empty pdf
I'm using reportlab to create a pdf. I am using Reportlab Paragraphs. The problem is everytime i download it, it generates an empty txt. I tested it without django and it works without a problem. If i'm using canvas it works but it doesn't suit what i need. views.py from django.http import HttpResponse from django.shortcuts import render from reportlab.lib.enums import TA_JUSTIFY from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle from reportlab.lib.pagesizes import letter def genereaza_pdf(request): if request.method == 'POST': response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename="example.pdf"' doc = SimpleDocTemplate("example.pdf", pagesize=letter, rightMargin=70, leftMargin=70, topMargin=70, bottomMargin=60) report = [] styles = getSampleStyleSheet() styles.add(ParagraphStyle(name="Times", fontName='Times-Roman', fontSize=15, alignment=TA_JUSTIFY)) p_text = "<u>ANEXA 1</u>" report.append(Paragraph(p_text, styles["Times"])) report.append(Spacer(1, 5)) doc.build(report) return response return render(request, 'pdf_test.html') pdf_test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Download pdf</title> </head> <body> <form method="POST"> {% csrf_token %} <button type="submit">Download</button> </form> </body> </html> What seems to be the problem? -
Django : Role based Access Control
How to implemet role based access control in Django? Managing different users based on their roles in a project like User, Admin, Manager ,Teacher ,etc., Is there any open source library available? I have read about User authentication in Django. Which deals with roles and groups. Can I define access for different type of users. -
How to stop Django caching view results
I am new to Django framework. I am using : python==2.7_win32 Django==1.11.3 djangorestframework==3.6.3 I am creating an API which do not involve any database. Flow of data is : User Request in JSON Invoking method in Django's views.py This method calls my local package that is not part of django and gets result Return this result in the Response Problem is : It works perfectly in the first request but on the next request it gives previous result only. I found that django caches the Queryset and we can force to read new data by adding all() method. But my code do not involve any Database or Model. So I think QuerySet will also not created.But still my results are getting cached somehow. how can I stop it? Here is my view : @api_view(['POST']) @never_cache def filter_details(request): data = {} data['data'] = {} result_array = [] error = None try: attr1 = request.data.get("attr1") attr2 = request.data.get("attr2") local_package_obj = local_package.ClassName(attr1) result_array = local_package_obj.get_some_data_as_array(attr2) except Exception as e: error = str(e) data['data']['important'] = result_array data['error'] = error return Response(data) Even after applying different values for att1 and attr2 I am getting same results. I have checked local package. I works properly. The … -
Dependency installation for Python (Django) project
I'm new to Python, but I had a requirement at my work-place. Another programmer is developing a project on Python, Django framework, and my task is to find a way in which this project will be executed at any computer. So, I'm talking about something like Composer for PHP. I need an easiest way that at debian branch to write in terminal a command, that will find kind of "composer.json" file on that project, will read all the required software, modules, libraries and install it step-by-step on PC. Any ideas how to do it in the easiest way? Thanks. -
Can't import modules - ImportError: No module named
I've created a new app called engineapp. Inside this app, there is a folder engine which is a Scrapy project. When I try to import model from storage app inside top.py file, it returns: from storage.models import TopItem ImportError: No module named storage.models Or the similar problem, when I try to import settings of scrapy project: from engineapp.engine.engine import settings It returns: from engineapp.engine.engine import settings ImportError: No module named engineapp.engine.engine This is when I run scrapy project from command line. Both imports created PyCharm itself. As you can see, I've added __init__() everywhere so python would be able to recognize those files. Do you know what should I do to be able to import those files? -
Filtering using the length of a feature in a IntegerRangeField
Is it possible to filter using the length (i.e. end - start) of a django.contrib.postgres IntegerRangeField? For example, if I have the following model: from django.contrib.postgres.fields import IntegerRangeField from django.db import models class Event(models.Model): name = models.CharField(max_length=200) position = IntegerRangeField() I would like to write a query something like: events = Event.objects.filter(position__length_gt=500) Where the filter statement would be the equivalent to: (position.upper - position.lower) > 500. Is there any way to achieve this either with the django orm or using raw sql? -
how to render <br /> to a new line in django template?
I am trying to render a message in a template using django. I used this code: message = "hello <br /> how are you? " t = loader.get_template(template_html) context = {"message":message} return t.render(context) The problem is that: I get hello <br /> how are you? in the template instead of a new line, how can I fix this? -
Upload images with Django
I'm trying to upload photos using Django as backend. The model that I use is: def inspection_picture_path(self, filename): return 'inspection_{0}/{1}'.format(self.inspection.id, filename) class InspectionPictures(models.Model): inspection = models.ForeignKey(Inspection, on_delete=models.CASCADE) picture = models.FileField(upload_to=inspection_picture_path, blank=True) def __str__(self): return "Inspection-{}".format(self.inspection.id) In settings.py I have : MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'master/static/master/img/inspection_pictures'), STATICFILES_DIRS = (os.path.join(BASE_DIR, 'master/static/master/img/inspection_pictures'),) The function in the view where I'm trying to save the images is as follows: def save_pictures(inspection, pictures): print(pictures) for picture in pictures['pictures']: n_picture = InspectionPictures() n_picture.inspection_id = inspection.id n_picture.picture = picture n_picture.save() print(pictures) gives me following result: <MultiValueDict: {'pictures': [<InMemoryUploadedFile: samsung-s8.png (image/png)>, <InMemoryUploadedFile: Simulator Screen Shot 6 Jul 2017, 15.43.55.png (image/png)>]}> Thus, the images are there but when I try to save them I get an error: AttributeError: 'bytes' object has no attribute '_committed' Any idea what I'm doing wrong? -
NoReverseMatch at /booking in django
{% extends 'booking/base.html' %} {% block title %} Booking {% endblock %} {% block content %} <div class="container"> <div class="row centered-form"> <div class="col-xs-12 col-sm-10 col-md-6 col-sm-offset-1 col-md-offset-3"> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">{% block title_text %}Booking Test{% endblock %}</h3> </div> <div class="panel-body"> <form role="form" method ="POST" action="{% url 'flightBooking' %}"> {%csrf_token %} <div class="row"> <div class="col-xs-6 col-sm-6 col-md-6"> <div class="form-group"> <!--input type="dropdown" name="first_name" id="first_name" class="form-control input-sm" placeholder="First Name"> </div--> <select name="fromLocation" class="form-control input-sm"> <option>From</option> {% for loc in location %} <option value="{{ loc.id }}">{{ loc.name }}</option> {% endfor %} </select> </div> </div> <div class="col-xs-6 col-sm-6 col-md-6"> <div class="form-group"> <select name="toLocation" class="form-control input-sm"> <option placeholder="To">To</option> {% for loc in location %} <option value="{{ loc.id }}">{{ loc.name }}</option> {% endfor %} </select> </div> </div> </div> <div class="row"> <div class="col-xs-6 col-sm-6 col-md-6"> <div class="form-group"> <!--input type="password" name="password" id="password" class="form-control input-sm" placeholder="Password"--> <input class="form-control input-sm" placeholder="Start Date" type="text" id="start_datepicker" name="fromDate"> </div> </div> <div class="col-xs-6 col-sm-6 col-md-6"> <div class="form-group"> <!--input type="password" name="password" id="password" class="form-control input-sm" placeholder="Password"--> <input class="form-control input-sm" placeholder="End Date" type="text" id="end_datepicker" name="toDate"> </div> </div> </div> <input type="submit" value="Search" class="btn btn-info center-block"> <div class="col-xs-6 col-sm-12"> <span class="text-danger small">{{ form.non_field_errors }}</span> </div> </form> </div> </div> </div> </div> </div> {% endblock %} I want to … -
Encryption of ID in Django using sqlite3 while storing the ID in database
I have been trying to save a model using django and sqlite3 through a form. Here are the codes to it: This is the /home/secure/secure_db/urls.py: from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name='index'), url(r'^create/$',views.create_db, name='create_db') ] This is the /home/secure/secure_db/views.py from django.http import HttpResponse from django.shortcuts import render from .models import Detail from passlib.hash import pbkdf2_sha256 def index(request): template = 'index.html' return render(request, template) def create_db(request): if request.method == 'POST': id = request.POST['id'] name = request.POST['name'] enc_id = pbkdf2_sha256.encrypt(id, rounds=12000, salt_size=32) Detail.objects.create( id = enc_id, name = name ) return HttpResponse('') This is the /home/secure/secure_db/models.py from django.db import models from passlib.hash import pbkdf2_sha256 class Detail(models.Model): id = models.IntegerField(primary_key=True, unique=True) name = models.CharField(max_length=100) def verify_id(raw_id): return pbkdf2_sha256.verify(raw_id, self.id) This is the /home/secure/secure_db/templates/index.html <html> <head> <script type="text/javascript" > $(document).on('submit','#new_user_form',function(e) { e.preventDefault(); $.ajax({ type:'POST', url:'/secure_db/create', data:{ id:$('#id').val(), name:$('#name').val(), csrfmiddlewaaretoken:$('input[name=csrfmiddlewaretoken]').val() }, success:function () { alert("Created New User"); } }); }); </script> </head> <body> <form id="new_user_form" method="post"> {% csrf_token %} User ID:<br> <input type="number" name="id" id="id"><br> Name:<br> <input type="text" name="name" id="name"><br> <input type="submit" value="SUBMIT"> </form> </body> </html> When I am navigating to http://localhost:8000/secure_db and entering the id and name, the alert is not appearing and the data are not … -
How to add "other" option in Django form with Javascript?
I'm using Django (1.11) with django-crispy-forms app. I have a view with form for editing instance of some model. There's some drop-down list for model's field (ForeignKey), and I want to add sth like "other" button below that, which (on click) will show some text input field with JS. Value of this text field have to be saved in another field of model, which is obviously TextField. I'm free to use jQuery, thanks in advance ;) -
Deploying project in Docker with Angular 4 with Django and postgresql
I am trying to deploy on Heroku my project in Docker with Angular 4 frontend with Django backend and postgresql database. At this moment my files looks as shown below. I am note sure if this is done properly? I have pushed it using heroku container:push web --app myproject but it doesn't work. My logs: 2017-07-07T10:27:30.448951+00:00 heroku[web.1]: State changed from crashed to starting 2017-07-07T10:27:30.436282+00:00 heroku[web.1]: Process exited with status 0 2017-07-07T10:27:50.846928+00:00 heroku[web.1]: Starting process with command `python3` 2017-07-07T10:27:53.350381+00:00 heroku[web.1]: Process exited with status 0 2017-07-07T10:27:53.365013+00:00 heroku[web.1]: State changed from starting to crashed 2017-07-07T10:27:53.876208+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=e1f8edfc-7dc4-4bd3-91be-0a853e948452 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:28:43.444860+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=361846d1-41cd-403a-989f-4c29a0d1179e fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:28:43.984059+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host= myproject.herokuapp.com request_id=658795c8-0ba7-4988-9d39-34601b1334c7 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:28:44.673789+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=63fbabdc-7ba7-4997-81be-c601a0d83368 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:29:53.091547+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=a3943544-9dc4-44f0-b788-a462cdfba7d0 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https 2017-07-07T10:29:54.419623+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=eb5191e2-21d9-410c-823e-c57bb0fb7fa4 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https … -
How to concat two columns of table django model
I am implementing search in my project what i want is to concat to column in where clause to get results from table. Here is what i am doing if 'search[value]' in request.POST and len(request.POST['search[value]']) >= 3: search_value = request.POST['search[value]'].strip() q.extend([ Q(id__icontains=request.POST['search[value]']) | (Q(created_by__first_name=request.POST['search[value]']) & Q(created_for=None)) | Q(created_for__first_name=request.POST['search[value]']) | (Q(created_by__last_name=request.POST['search[value]']) & Q(created_for=None)) | Q(created_for__last_name=request.POST['search[value]']) | (Q(created_by__email__icontains=search_value) & Q(created_for=None)) | Q(created_for__email__icontains=search_value) | Q(ticket_category=request.POST['search[value]']) | Q(status__icontains=request.POST['search[value]']) | Q(issue_type__icontains=request.POST['search[value]']) | Q(title__icontains=request.POST['search[value]']) | Q(assigned_to__first_name__icontains=request.POST['search[value]']) | ]) Now i want to add another OR condition like CONCAT(' ', created_by__first_name, created_by__last_name) like '%'search_value'%' But when i add this condition in queryset it become AND where = ["CONCAT_WS(' ', profiles_userprofile.first_name, profiles_userprofile.last_name) like '"+request.POST['search[value]']+"' "] tickets = Ticket.objects.get_active(u, page_type).filter(*q).extra(where=where).exclude(*exq).order_by(*order_dash)[cur:cur_length] how to convert this into OR conditoin. Thanks in advance. -
Upload, modify and play a video in Django
I want to build an interface in Django where the user can upload a video. My python code should run on the video and subsequently my web application should be able to play the modified(basically, with bounding boxes around objects of interest) video. How do I: Allow the user to upload large sized video files? Link my Django code to Python? Display the modified video on the web app? -
Django: How to mention number of process? like how it is done with Flaks
I am trying to create a simple Fibonacci web service with * Django and * Flask I am using djangorestframework and flask_restful I am doing this to make some comparison. with Flask I am able to specify the number of process or to use threading etc. with Api in flask_restful from flask import Flask, request, Response, jsonify from flask_restful import abort, Resource, Api, reqparse api = Api(app) api.add_resource(Test, '/test/') app.run(port=1234, host='0.0.0.0', threaded=True) #processes=50) My question, how to specify the same in django rest framework? From the docs I am not able to find a straight forward answer, yet.. -
Could Not Connect to Instance Server in Google Cloud Platform
I'm trying to deploy my app to GCP under Flexible App development. I'm using Django 1.9 and postgresql. I've created my Google Cloud SQL instance and have enabled the SQL api in my API Manager. I've also given Admin roles to my project for Cloud SQL. Right now I'm encountering this problem: Is the server running locally and accepting connections on Unix domain socket "/cloudsql/<instance-connection-name>/.s.PGSQL5432"? My app.yaml are also correct. My credentials for my user, db name, and password are all correct. How do I fix this problem? -
Django Rest Framework get login method used
I'm using Django Rest Framework with django-oauth-toolkit for oauth2 and django-rest-auth for social login, and I need to know how a user logged in, so I can manage password change for instance. Until now, the only way I found is getting request.auth._meta.app_label, which will be oauth2_provider for oauth login or authtoken for Facebook login, as the latter uses a normal DRF token, but I think this isn't specific enough. Is there a way of knowing exactly how a user logged in? -
@method_decorator working ambiguity
class find_user(ListAPIView): serializer_class = AuthUserSerializer def get_queryset(self): """ Optionally restricts the returned purchases to a given user, by filtering against a username query parameter in the URL. """ userstring = self.kwargs['username'] if userstring is not None: queryset = AuthUser.objects.filter(Q(username__icontains=userstring) | Q(email__contains=userstring))[:10] return queryset @method_decorator([login_required, group_required('scoreUpdate')]) def dispatch(self, *args, **kwargs): return super(find_user, self).dispatch(*args, **kwargs) This needs me to pass a decorator over dispatch as is the norm for class based views. Can anyone please explain how this works? class TestApi(APIView): @method_decorator([login_required, group_required('scoreUpdate')]) def get(self, request, *args, **kw): get_arg1 = request.GET.get('arg1', None) get_arg2 = request.GET.get('arg2', None) result = {1: get_arg1, 2: get_arg2} return Response(result, status=status.HTTP_200_OK) Does @method_decorator behave differently in anyway? Thanks in advance. -
How do I retrieve and return an instance from my Class-Based Detail view?
I have two linked models: class MyUser(AbstractBaseUser, PermissionsMixin): username = models.CharField(max_length=24, unique=True) profile_page = models.OneToOneField(Profile, null=True) class Profile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True) I am attempting to retrieve and return an instance of a single user's profile in this CBV: class ProfileView(DetailView): queryset = Profile.objects.all() template_name = 'profile_detail.html' def get_object(self, *args, **kwargs): user_profile = self.kwargs.get('username') obj = get_object_or_404(Profile, user=user_profile) return obj The get_object_or_404 call causes the following exception: invalid literal for int() with base 10: 'adam' "adam" because I am requesting the page url: http://127.0.0.1:8000/profile/adam Here are my url patterns: urlpatterns = [ url(r'^edit/', profile_edit, name='profile_edit'), url(r'^(?P<username>[\w.@+-]+)$', ProfileView.as_view(), name='profile'), ] (Just in case: these also belong in the namespaced /profile/) I'm trying to access the model fields within the Profile model. Why is it that I receive the error when trying to return obj to my profile_detail.html template? What I've tried: If I change the URL regex to accept ID or PK instead of <username> and access the url of /profile/1, I receive: TypeError at /profile/1 __str__ returned non-string (type MyUser). If I then update my code to be: def get_object(self, *args, **kwargs): user_profile = self.kwargs.get('id') obj = get_object_or_404(Profile, user=user_profile) objj = obj.user return objj then the errors clear … -
i want show table from database using datatable and orderlistjson class in django
i'm using django and datatable and sql db, with json. i want to fetch fname and id from table tbl_user in database ,and whose model class is TblUser, i want to use datatable and orderlistjson, here is my main project file model.py class TblUser(models.Model): business_id = models.IntegerField() zoom_uid = models.CharField(max_length=255) zoomtoken_id = models.TextField() email = models.CharField(max_length=200) through = models.IntegerField() countrycode = models.CharField(db_column='countryCode', max_length=255) # Field name made lowercase. phone = models.BigIntegerField(blank=True, null=True) password = models.TextField() dob = models.CharField(max_length=100) sex = models.CharField(max_length=50) fname = models.CharField(max_length=100) lname = models.CharField(max_length=90, null=True, blank=True) my_personal_code = models.CharField(max_length=250) refer_id = models.IntegerField(blank=True, null=True) status = models.IntegerField(blank=True, null=True) free_visits = models.IntegerField(blank=True, null=True) latitude = models.FloatField(blank=True, null=True) longitude = models.FloatField(blank=True, null=True) date_created = models.DateTimeField(auto_now_add=True) date_updated = models.DateTimeField(auto_now=True) email_verified = models.IntegerField(null=True, default=False) # 0-> not verified 1 -> verified def __unicode__(self): return u'%s' % (''.join([self.fname, ' ', self.lname , '(' , self.email ,')' ])) class Meta: managed = False db_table = 'tbl_user' index.html(template file) {% extends 'includes/base.html' %} {% load staticfiles %} {% load filters %} {% block content %} <link rel="stylesheet" href="{% static 'css/jquery-ui.css' %}"> <script type="text/javascript"> /* Custom filtering function which will search data in column four between two values */ $(function (){ $("#from, #to, #fordate").datepicker({ changeMonth: true, …