Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
No 'Access-Control-Allow-Origin' using django rest framework api
pip3 install django-cors-headers Requirement already satisfied: django-cors-headers in /usr/local/lib/python3.6/site-packages You are using pip version 9.0.1, however version 9.0.3 is available. You should consider upgrading via the 'pip install --upgrade pip' command. I've ran the following command: I then set it in my INSTALLED_APPS respectivelikey like this: INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'corsheaders' ] I then use it in middleware like this, MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware' 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] I get following error: ModuleNotFoundError: No module named 'corsheaders.middleware.CorsMiddlewaredjango'; 'corsheaders.middleware' is not a package The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper fn(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 140, in inner_run handler = self.get_handler(*args, **options) File "/usr/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler handler = super().get_handler(*args, **options) File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 65, in get_handler return get_internal_wsgi_application() File "/usr/local/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application ) from err django.core.exceptions.ImproperlyConfigured: WSGI application 'instawork.wsgi.application' could not be loaded; Error importing module. I've followed strict instructions, I'm currently using latest django framework too. -
Import / migrate old (Django 0.97) model data into Django 1.8 or higher
What would be the best approach to migrating or importing data from a very old Django app (0.97) to a relatively "modern" Django release (1.8)? The application (if you can call it that) is little more than a series of models and some simple views. The users primarily accessed it via the admin UI (I know, I know). So in terms of code to convert, there's very little. I've updated the models.py to be 1.8-friendly, and I can easily spin up an empty instance of the app without difficulty. However, I run into problems once I try to get the old data in the system. I thought I'd try dumpdata/loaddata, but didn't expect it to work (and it didn't). I get a number of errors along these lines: django.db.utils.IntegrityError: Problem installing fixture 'olddata.json': Could not load contenttypes.ContentType(pk=6): duplicate key value violates unique constraint "django_content_type_app_label_5fd9156b761d2158_uniq" DETAIL: Key (app_label, model)=(contenttypes, contenttype) already exists. Before I dive into the depths of the export file, I want to be sure that I'm on the right track. Is there a better way to do this? -
Opening Existing Django Project in Visual Studio
I've been using Jetbrains Pycharm for years, but lately the performance has been getting abysmal. I'd like to give Visual Studio a shot. So I cloned my main repo, through VS, and tried to setup a "Solution". It doesn't seem to recognize my project. In Pycharm I could just clone any old repo, open the folder and then select the interpreter/env I wanted to run it in. I've kinda got it working by creating a django project in VS and then loading all my files in, but that doesn't seem right or viable. Any tips on how to setup/create a "Solution" for a cloned django project? -
django: template file not found
I am trying to integrate my angular 4 app into django. Regarding using django I am familiar with building REST Endpoints not templates. in my template views.py file I have the class RootView when I request my index.html file from my templates folder. is there a quick fix? currently searching as well. from django.shortcuts import render from django.views.generic import TemplateView def error_404(request): data = {} return render(request, 'index.html', data) class RootView(TemplateView): def get(self, request, **kwargs): return render(request, 'index.html', context = None) -
Django 2.0.3 Many errors
I'm newbie at Django and I have a problem. I use Win 7 for my Python project and when I try to start manage.py I have this: c:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64>python cloudli b\manage.py runserver Performing system checks... System check identified no issues (0 silenced). You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. March 27, 2018 - 20:27:14 Django version 2.0.3, using settings 'cloudlib.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. Unhandled exception in thread started by .wrapper at 0x0000000004167158> Traceback (most recent call last): File "c:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\django\utils\autoreload.py", line 225, in wrapper fn(*args, **kwargs) File "c:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\django\core\management\commands\runserver.py", line 142, in inner_ru n ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls) File "c:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\django\core\servers\basehttp.py", line 163, in run httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6) File "c:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\si te-packages\django\core\servers\basehttp.py", line 66, in init super().init(*args, **kwargs) File "c:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\so cketserver.py", line 453, in init self.server_bind() File "c:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\ws giref\simple_server.py", line 50, in server_bind HTTPServer.server_bind(self) File "c:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\ht tp\server.py", line 138, in … -
Django Nested Form - Always Showing Object instead of model details
I'm working on a Django project generated via Mezzanine. I've been able to create my models, however I want to have a form where an admin can select from a list to assign a value in a many to many or a one to many relationship. For example, I have a model for Schemas: class Schema(AutoCreatedUpdatedMixin, SoftDeleteMixin): """List of all Schemas in a given database""" name = models.CharField(max_length=128, null=False) status = models.BooleanField(max_length=128, null=False, default=True, verbose_name="Is Active") description = models.CharField(max_length=65535, null=True, blank=True, default=None) database = models.ForeignKey(Database, on_delete=models.CASCADE) pull_requests = models.ManyToManyField(Link) questions = models.ManyToManyField(Question, blank=True) comments = models.ManyToManyField(Comment, blank=True) technical_owners = models.ManyToManyField(Employee, related_name='technical_owners_schemas', blank=True) business_owners = models.ManyToManyField(Employee, related_name='business_owners_schemas', blank=True) watchers = models.ManyToManyField(Employee, related_name='watchers_schemas', blank=True) def __unicode__(self): return "{}".format(self.name) And I have a model for Employees class Employee(AutoCreatedUpdatedMixin, SoftDeleteMixin): """List of people with any involvement in tables or fields: business or technical owners, developers, etc""" name = models.CharField(max_length=256, blank=False, null=False, default=None, unique=True) email = models.EmailField(blank=True, null=True, unique=True) def __unicode__(self): return "{}".format(self.employee) An employee can own multiple schemas and a schema can be owned by multiple employees. My database has an active employee in it, however when I try to create a Schema the employee shows up as Employee Object. Rather I would want … -
Django views on articles
How to count the number of unique views on articles? class Article(models.Model): title = models.CharField(max_length = 300) post = RichTextUploadingField(blank=True, default='') date = models.DateTimeField(auto_now=True) def __str__(self): return "%s" % (self.title) -
A confused about database structure and displacement on django admin
I am currently working on django and get confused about how to design the model. Right now, I have a table named 'Reactionmeta' which structure like below: 1 2 3 4 5 6 reaction name metabolite1 stoichiometry1 ....... metabolite60 stoichiometry60 (stoichiometry1 corresponds to metabolite1 and so on so forth) (P.S: I have to claim that each stoichiometry correspond to one metabolites in the reaction, like a + b -> 2c + d(the number is the stoichiometry) However, one metabolite may has different stoichiometry, because they may involved in different reactions. For example: a + 2b + c -> d + e + f; 2a + b -> h + j (metabolite a has different stoichiometry in two reactions) some of the reactions, contains 2 metabolites, thus this reaction have value in 6 columns and no value from column 7-122. And some of the reactions contains more than 40 metabolites, so they have values in majority of columns. My question is, I created the class and registered in the admin.py, and when I clicked on one reaction in adminsite and all the columns are displayed even though some of fields are blank, like below: In that case, how can only display … -
2 docker containers (Django & React), isomorphic-fetch and a login request
This cookiecutter setup is running on Docker with a frontend (React) as well as a backend (Django) container. I'm using the login-form component of the drf-react-app below in another project and am clueless as to how the api fetch request in the loginUser action creator (src/actions/user.js) knows which URL it is supposed to use..? user.js:22 POST http://localhost:3000/api/obtain-auth-token/ 404 (Not Found) I want it to send the request to the server at port 8000. I took the code from this drf-react boilerplate: https://github.com/moritz91/drf-react-login What am I missing? -
DRF update or create object
guys in my app each product must have only one record for discount in table. i have this view for create new record in db .. how can i tell if object with comming product id is availible in db just update the target column otherwise create new object ? some people use def create in serializer should i use that function or something else ??? class DiscountControllAPiView(APIView): """ each product may takes a discount code or percent from owner or site administrator """ def post(self,request): serializer = ProductDiscountControllSerializer(data=request.data) if(serializer.is_valid()): serializer.save() return Response(True) else: return Response(serializer.errors) related serilizer : class ProductDiscountControllSerializer(ModelSerializer): class Meta: model = ProductDiscountControll fields = [ 'product', 'discount', 'discount_code', 'discount_code_precent', ] -
Django Forms: styling forms (checkboxes) manually - Input to be outside of label
I need to render checkbox form fields in the following format in html template: <input id="tag" type="checkbox" name="check" value="1"> <label for="tag">Tag 1</label> Currently, in my template I tried: {{ filter.form.tags.errors }} {% for field in filter.form.tags %} <input id="{{ field.id_for_label }}" type="checkbox" name="check"> <label for="{{ field.id_for_label }}">{{ field.value }}</label> {% endfor %} This will not render {{ field.value }} (I get empty instead of Tag 1) and also is non sticky. I also tried: {% for field in filter.form.tags %} {{ field.label_tag }} {{ field }} {% endfor %} Which gives me nested of <label><input></input></label>, but displays everything that I need. Is it possible to render a form such that I get the format that I'm after? (It should also preserve checked e.g. make ticks sticky). -
Daphne server gives "Exception Inside Application" and no other information
I'm trying to get my Django channels based project up and running. ./manage.py does the trick, but I'm attempting to start it using something like Heroku CLI, Foreman, or plain ol daphne config.asgi:application to get it running, since eventually I'll need it up on Heroku. Although the app runs with ./manage.py, it does not work when run with heroku local or when pushed to Heroku's server. I'm having an issue extracting any more information in order to debug. I don't seem to have a lot to work with. Running daphne config.asgi:application -b 0.0.0.0 -p 8001 -v2 will output: 2018-03-28 01:41:56,045 DEBUG Importing BmpImagePlugin 2018-03-28 01:41:56,054 DEBUG Importing BufrStubImagePlugin 2018-03-28 01:41:56,056 DEBUG Importing CurImagePlugin 2018-03-28 01:41:56,056 DEBUG Importing DcxImagePlugin 2018-03-28 01:41:56,058 DEBUG Importing DdsImagePlugin 2018-03-28 01:41:56,059 DEBUG Importing EpsImagePlugin 2018-03-28 01:41:56,077 DEBUG Importing FitsStubImagePlugin 2018-03-28 01:41:56,079 DEBUG Importing FliImagePlugin 2018-03-28 01:41:56,080 DEBUG Importing FpxImagePlugin 2018-03-28 01:41:56,082 DEBUG Image: failed to import FpxImagePlugin: No module named 'olefile' 2018-03-28 01:41:56,083 DEBUG Importing FtexImagePlugin 2018-03-28 01:41:56,088 DEBUG Importing GbrImagePlugin 2018-03-28 01:41:56,089 DEBUG Importing GifImagePlugin 2018-03-28 01:41:56,092 DEBUG Importing GribStubImagePlugin 2018-03-28 01:41:56,093 DEBUG Importing Hdf5StubImagePlugin 2018-03-28 01:41:56,095 DEBUG Importing IcnsImagePlugin 2018-03-28 01:41:56,099 DEBUG Importing IcoImagePlugin 2018-03-28 01:41:56,100 DEBUG Importing ImImagePlugin 2018-03-28 01:41:56,105 DEBUG Importing ImtImagePlugin … -
Ajax call to a django view is returning an array of strings
I am new django and ajax and i am trying to send a post request to django view when a user clicks on a button in my html page. The django view has to return a json object when I tried to do that it gives me an error saying TypeError: Object of type 'QuerySet' is not JSON serializable How can we send an Object type serializable in django. Manage_project.html <form action="{% url 'supervisor:manageproject' %}" id="my_form" method="post"> {% csrf_token %} <input type="hidden" name="project_id", value={{project.id}}> <div class="form-group row"> <label for="projectName" class="col-sm-2 col-form-label">Project Name</label> <div class="col-sm-10"> <input type="text" name="project" class="form-control-plaintext" id="projectName" value="{{project.project_name}}"> </div> </div> <h6>Manage the employees list:</h6> <p>Check the boxes to remove employees:</p> <div class="container"> <div class="row"> <div class="col-xs-6"> <table class="table"> {% for employee in employees_could_add.all %} <tr> <td><input type="checkbox" name="employees_inproject" value="{{employee.id}}"> {{employee}}</td> </tr> {% endfor%} <tr> <td><button class="btn btn-primary" name="perform" value = "Add" type="submit">Add Employees</button></td> </tr> </table> </div> <div class="col-xs-6"> <table class="table"> {% for employee in project.employees.all %} <tr> <td><input type="checkbox" name="employees" value="{{employee.id}}"> {{employee}}</td> </tr> {% endfor%} <tr> <td><button class="btn btn-danger" name="perform" value="delete" type="submit">Delete</button></td> </tr> </table> </div> </div> </div> </form> ajaxcalls.js $(document).ready(function() { //alert("hi") $('#my_form').submit(function(e) { // catch the form's submit event // e.preventDefault() //console.log($(this)) $.ajax({ // create an AJAX … -
Django user turns into Anonymous User
I'm trying to perform django authentication using a custom user model. Note this is for a school project and not I have the following User model class User(AbstractBaseUser): userID = models.AutoField(primary_key=True) username = models.CharField(max_length=20, unique=True) password = models.CharField(max_length=24) first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=50) USERNAME_FIELD = "username" REQUIRED_FIELDS = ["first_name", "last_name"] def get_full_name(self): return self.first_name + " " + self.last_name def get_short_name(self): return self.username class Meta: db_table = "User" app_label = "funbids" managed = False I have my model defined in settings.py AUTH_USER_MODEL = 'funbids.User' I'm also using a custom auth backend. Note this is just a test using cleartext passwords (I'm aware this is a terrible idea to do in any production environment). I'm using a custom auth backend because a requirement for this app is to authenticate using raw SQL queries with an existing database. class AuthBackend(object): """ Authenticate a user in funbids """ def authenticate(self, request, username=None, password=None): # Test credentials cursor = connections["funbids"].cursor() cursor.execute("SELECT 1 FROM User WHERE username=%s AND password=%s", [username, password]) if cursor.fetchone(): # Have to grab the model, then authenticate user = User.objects.get(username=username) return user else: return None def get_user(self, user_id): try: return User.objects.get(username=user_id) except User.DoesNotExist: return None Everything seems to work in … -
django-geoext sample cannot import name execute_manager
hello I wanto to run this example django-geoext from GitHub but I take error ImportError: cannot import name execute_manager any idea ho to can fix that ? code of manage.py : #!/usr/bin/env python from django.core.management import execute_manager import imp try: imp.find_module('settings') # Assumed to be in the same directory. except ImportError: import sys sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) sys.exit(1) import settings if __name__ == "__main__": execute_manager(settings) error message : Traceback (most recent call last): File "C:/Users/username/Desktop/django-geoext-sample-master/manage.py", line 2, in <module> from django.core.management import execute_manager ImportError: cannot import name execute_manager -
Importing defined functions from one .py file to another .py file in Django
So I am trying to create a website and I have my html working 100% on a local host using django. At the moment my code is not associated with the html so if I put in a username and password, the page does nothing, which makes sense. I am at the point where I am trying to import a defined function from my .py file with all my code(b.py) and I have another file (a.py) which essentially should take the information from the defined functions of b.py, use the information, then display it on the localhost webpage. But my issue is that it is saying *ImportError: cannot import name 'definedfunctionname'. Both a.py and b.py are in the same directory as eachother. -
Django multiple widgets in one modelform field
I have the following model and modelform: class Course(models.Model): duration = models.CharField(max_length=100, blank=True,null=True) class NewCourseForm(ModelForm): class Meta: model = Course fields = ['duration',] When rendering the form, I want the user to select a number, and time unit. E.g. 2 weeks. It should look something like: Duration <input type='number', name='duration_number'> <select name='duration_unit'> <option>Hours</option> <option>Days</option <option>Weeks</option> <option>Months</option> <option>Years</option> </select> In the view, I will combine these two values into a string e.g. '2 Weeks' which will be saved in the duration field. How can I get my modelform to render as above? I know I could make a separate table for the duration with a OneToOne relationship, but wont the join when performing lookups will slow things down ? -
Django: Image Resizing & Compression
I'm working on a django project in which users can upload images. Here's the view, class AllPictures(models.Model): profile = models.ImageField(upload_to='profile_image', blank=True) // But before saving the image i'm compressing & resizing it, here's how def save(self, *args, **kwargs): if self.profile: img = Image.open(self.profile) resize = img.resize((240, 240), Image.ANTIALIAS) new_image = BytesIO() resize.save(new_image, format=img.format, quality=75) temp_name = self.profile.name self.profile.save(temp_name, content=ContentFile(new_image.getvalue()), save=False) super(AllPictures, self).save(*args, **kwargs) But the problem is that when i upload images then instead of saving them directly inside the profile_image folder, it creates a long series of sub-sub-folders for every new image & saves that image inside a separate folder. So, the profile_image folder looks something like this, profile_image my_image.png ----profile_image new_image.png --------profile_image all_image.png ------------profile_image images.png ----------------profile_image picture.png --------------------profile_image another_pic.png & so on . . . How can we save all new images in just 1 folder & prevent the formation of these sub-folders? Thank You! -
django angular 4 heroku The requested URL /suitsadmin was not found on this server
I have an angular app being served on the root of my server. Then the server acts like a restful api for the app. here is my urls.py urlpatterns = [ url(r'^/$', serve, kwargs={'path': 'index.html'}), url(r'^(?!/?static/)(?!/?media/)(?P<path>.*\..*)$',RedirectView.as_view(url='/static/%(path)s', permanent=False)), url(r'api/',include(rootapi)), ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) I also tried the first url without the / which also didnt work. in my angular app I have this in my index.html page. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Suits + Tables</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> </head> <body> <app-root></app-root> </body> the base href="/" I am not sure how to fix this. My logs are fine. Currently researching it. Can someone please explain what is going on? this question seems to be in the same alley but not sure if same problem Angular - The requested URL /home was not found on this server -
Django custom User not registering with Admin
I've followed the documentation at https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#substituting-a-custom-user-model, but for some reason things still aren't working for me. I can create and login to User accounts, but for some reason I can't view them with the admin. This leads me to believe they're not being registered correctly, but as said before, I've followed the documentation on how to do that: sign_up/models.py from django.contrib.auth.models import AbstractUser # Create your models here. class User(AbstractUser): pass sign_up/admin.py from django.contrib import admin from django.contrib.auth.admin import UserAdmin from .models import User # Register your models here. admin.register(User, UserAdmin) site/settings.py # define custom user model AUTH_USER_MODEL = 'sign_up.User' I've also tried deleting my database and migrations and reapplying them, but this still isn't helping. -
How can I implement in Django, Choices of Choices?
How can I implement in Django, Choices of Choices ? As widget, I'm thinking of a conditional select. So, in the first select, or radio buttons, the user selects, an option. Based on this option another select/radio group appears with the options associated with the selected previous option. I know, I can' try using FK or manytomany relations, but my choices are fixed. -
Having trouble displaying related fields in Django 2.0 template
I am a newbie to Django and cannot figure this out from any of my searches. I am having trouble displaying related fields in my Django 2.0 template. There are 2 fields in my model referring to the same foreign model. What is the best way to handle this? I greatly appreciate any assistance with this. Model class Clients(models.Model): company_name = models.CharField(max_length=150) type = models.ForeignKey(Types, on_delete=models.PROTECT) division = models.ForeignKey(Divisions, on_delete=models.PROTECT) address1 = models.CharField(max_length=150, null=True, blank=True) address2 = models.CharField(max_length=150, null=True, blank=True) city = models.CharField(max_length=150, null=True, blank=True) state = models.CharField(max_length=30, null=True, blank=True) zip = models.CharField(max_length=30, null=True, blank=True) name = models.CharField(max_length=150, null=True, blank=True) phone = models.CharField(max_length=75, null=True, blank=True) mobile = models.CharField(max_length=75, null=True, blank=True) fax = models.CharField(max_length=150, null=True, blank=True) email = models.EmailField(null=True, blank=True) website = models.URLField(null=True, blank=True) pb_support_rate = models.ForeignKey(SupportRates, null=True, on_delete=models.PROTECT, related_name='pb_rate', blank=True) px_support_rate = models.ForeignKey(SupportRates, null=True, on_delete=models.PROTECT, related_name='px_rate', blank=True) View class ClientsDetailView(DetailView): model = models.Clients context_object_name = 'client_details' template_name = 'client_details.html' Template <tr> <th style=" border: 1px solid black;padding: 0px 5px 0px 5px;white-space: nowrap;">PB Support Rate</th> <td style=" border: 1px solid black;padding: 0px 5px 0px 5px;white-space: nowrap;" >{{ object.pb_support_rate|default_if_none:'' }}</td> <td style=" border: 1px solid black;padding: 0px 5px 0px 5px;white-space: nowrap;text-align:right;" >{{ object.pb_rate__rate_amount }}</td> </tr> -
Django with Oracle database 11g
I am new to the python language and django. I need to connect the django to the oracle database 11g, I have imported the cx_oracle library and using the instant client for connecting oracle with django, but when i run the command manage inspectdb > models.py. I get error as Invalid column identifier in the models.py. How could i solve it. I have only 2 tables in that schema i am connecting? -
Django Checkboxes
I am trying to have a form in django that uses checkboxes. I can hard code them in the HTML but I wanted to do it the Django way. Forms.py checkbox = forms.BooleanField(widget= forms.CheckboxInput, label='Mycheckbox',) HMTL: {% for field in form %} <label for="{{ field.id_for_label }}">{{ field }}{{ field.label }}</label> {% endfor %} Right now the form only will display the checkbox but not the label that I designated. I can use {{field.name}} but that will give me the name of the variable in the forms but not the label that I want it to display. -
Trouble converting number from query result to float in the template
i have an sql stored procedure returning me values (Characteristics and their value). The values are real in the table, fixed to 2 decimals, the table doesn't seem to be the problem since the numbers are stored properly. The problem come when i load my template (i use Python+Django), those value are listed in a tab : <table id="regnorme3Tab" name="regnorme3Tab" class="display" width="100%" cellspacing="0"> <thead> <tr> <th>ID</th> <th>Code</th> <th style="width:200px">Libellé</th> <th>Limite inf</th> <th>Valeur</th> <th>limite sup</th> </tr> </thead> <tbody> {% for reg_norme in reg_savs %} {%if reg_norme.Saisie == 'O' %} <tr name="Reg_Normes" id="{{reg_norme.regauxnormes}}"> <th><span> {{reg_norme.Id}}</span></th> <th class="codevalue"><span> {{reg_norme.Code}}</span></th> <th style="width:200px"><span> {{reg_norme.LibEtendu}}</span></th> <th><span> {{reg_norme.LimitInf}}</span></th> <th><span><input type="number" max="{{reg_norme.LimitSup}}" step="0.01" min="{{reg_norme.LimitInf}}"class="{{reg_norme.Code}}" id="{{reg_norme.Id}}" value="{{reg_norme.Valeur}}" required style="width:40px;"></span></th> <th><span> {{reg_norme.LimitSup}}</span></th> </tr> {%endif%} {% endfor %} </tbody> </table> If i leave things like that, nothing is displayed in my input, i had the same problem on some isolated number input and i managed to display the data by using parseFloat() and toFixed(2). document.getElementById('ebHumValue').value = parseFloat({{displayHUMHumidite}}).toFixed(2); So i though i would create a function with a loop on my tab and use parseFloat and toFixed to display something. $("#regnorme3Tab :input").each(function () { var number = this.name; this.value = number; alert(parseFloat(this.name).toFixed(2)); }); The function is in document.ready so it would format …