Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django + Gunincorn - deploy and stay connected to the port?
Correct me if I am wrong: I can use gunicorn to deploy a django project, for instance I can deploy my app - helloapp in this way: $ cd env $ . bin/activate (env) $ cd .. (env) $ pip install -r requirements.txt (env) root@localhost:/var/www/html/helloapp# gunicorn helloapp.wsgi:application [2017-05-18 22:22:38 +0000] [1779] [INFO] Starting gunicorn 19.7.1 [2017-05-18 22:22:38 +0000] [1779] [INFO] Listening at: http://127.0.0.1:8000 (1779) [2017-05-18 22:22:38 +0000] [1779] [INFO] Using worker: sync [2017-05-18 22:22:38 +0000] [1783] [INFO] Booting worker with pid: 1783 So now my django site is running at http://127.0.0.1:8000. But it will not be available anymore as soon as I close/ exit my terminal. So how can I have it stayed connected to the port 8000 even if I have closed my terminal? -
reply to a user with the same role Django
I've solved my reply to comment and send a mail problem by using reply_to parameter from the django email documentation, and now the system works. New problem is that I'm replying to my self instead to the user who left the comment, now that is not so hard to solve, but the problem is that we all have a same role in the system an that is we are account_handlers, and everything regarding email to a comment system is happening internally in the system, so client are not receiving anything. So currently when I send and email the response header is ok: Content-Type: multipart/alternative; boundary="===============7401208332011429127==" MIME-Version: 1.0 Subject: Talkbridge OS: Comment posted on Client q2651652614 From: system@mysystem.com To: you.handler@system.com Date: Fri, 19 May 2017 08:12:28 -0000 Message-ID: <20170519081228.6714.42106@vagrant.vm> and when a user reply to my comment: Content-Type: multipart/alternative; boundary="===============2754524254860151373==" MIME-Version: 1.0 Subject: Talkbridge OS: Reply to comment posted on Client q2651652614 From: system@mysystem.com To: you.handerl@talkbridge.com Reply-To: you.handler@talkbridge.com Date: Fri, 19 May 2017 08:33:15 -0000 Message-ID: <20170519083315.6714.42306@vagrant.vm> As you can see in Reply-To: you.handler@talkbridge.com should be different mail address. From the title I've stated that we all have the same role and that is account_handler = models.ForeignKey(User, blank=True, null=True, related_name='handling_leads', on_delete=models.SET_NULL) … -
Django has no Foreign Key Error with Inline Admin Models
I'm trying to use a TabularInline in Django Admin UI and I got an error which I understand in theory, but with the code I don't, it seems correct for me, I must miss something. Here is part of my admin.py class DependenciesInline(admin.TabularInline): model = Dependency @admin.register(Dependency) class DependencyAdmin(admin.ModelAdmin): list_display = ('name',) @admin.register(Environment) class EnvironmentAdmin(admin.ModelAdmin): inlines = [DependenciesInline] pass Here is part of my models.py class Environment(models.Model): name = models.CharField(max_length=128) makefile = models.TextField() script = models.TextField() def __str__(self): return self.name class Dependency(models.Model): name = models.CharField(max_length=128) environment = models.ForeignKey(Environment, on_delete=models.CASCADE) def __str__(self): return self.name Here is the error I get : Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10ebac378> Traceback (most recent call last): File "/Users/anthony/development/internship_ecam/python/pythia-studio/virtualenv/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper fn(*args, **kwargs) File "/Users/anthony/development/internship_ecam/python/pythia-studio/virtualenv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run self.check(display_num_errors=True) File "/Users/anthony/development/internship_ecam/python/pythia-studio/virtualenv/lib/python3.6/site-packages/django/core/management/base.py", line 405, in check raise SystemCheckError(msg) django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues: ERRORS: <class 'studio.admin.DependenciesInline'>: (admin.E202) 'studio.Dependency' has no ForeignKey to 'studio.Environment'. I don't understand why it's saying that I lack a FK form Dependency to Environment as there is clearly one. -
MultipleChoiceField on multiple columns
I have a form in django: country=forms.MultipleChoiceField(choices=lista_tari, widget=forms.CheckboxSelectMultiple(),required=True) What i want is to display this form on multiple columns in the webpage. There are 30 choices, i want them on 6 or 5 or whatever columns. This is the search.html: {% block content%} <form method="POST" class="post-form">{% csrf_token %} {{ form.as_p }} <button type="submit" class="save btn btn-default">Save</button> </form> {% endblock %} I am brand-new to css, html and even django so any help would be of great help. Thank you! -
In Django, how can I understand include() function?
I have started learning Django, I'm not sure what the include() function means. Here is mysite/urls.py. - project from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^polls/', include('polls.urls')), url(r'^admin/', admin.site.urls), ] Here is polls/urls.py. - app in project from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name='index'), ] From django document, include() function was described as follows. Whenever Django encounters include(), it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing. I'm not sure what is that point, what is remaining string. In case of the example above, what is remining string, what is url strings which was chopped off? -
How to add extra fields in ValueQuerySet (Django)?
Basically, I want to convert the query_set to JSON. But I also want to add one more field something like size = some number in the query_set which is not present in the query_set attributes (it is computed attribute). Can you tell me how to do it? query_set = PotholeCluster.objects.all().values('bearing', 'center_lat', 'center_lon', 'grid_id') return JsonResponse(list(query_set), safe=False) I tried the code below query_set = PotholeCluster.objects.all() response_list = [] for pc in query_set: d = {} d['bearing'] = pc.get_bearing() d['center_lat'] = pc.center_lat d['center_lon'] = pc.center_lat d['grid_id'] = pc.grid_id d['size'] = pc.pothole_set.all().count() response_list.append(d) serialized = json.dumps(response_list) return HttpResponse(serialized, content_type='application/json') This code works fine. I make Ajax requests and I get the data in JSON. But this somehow doesn't plot the markers on Google maps and there is no error in the console also. On the other hand the first version works well. var map; var infoWin; var markerCluster; function initialize() { var center = new google.maps.LatLng(19.0760, 72.8777); map = new google.maps.Map(document.getElementById('map'), { zoom: 12, center: center, mapTypeId: google.maps.MapTypeId.ROADMAP, scaleControl: true }); infoWin = new google.maps.InfoWindow(); var options = { imagePath: '{% static "web/js/markerclusterer/images/m" %}', maxZoom: 17 }; var markers = []; markerCluster = new MarkerClusterer(map, markers, options); var styleIconClass = new StyledIcon( StyledIconTypes.CLASS, … -
CSS styling mistake
I need to apply this theme for my django template using css. I wrote the css file but i have a mistake that not all the style is applied to the template. Please any help. this is the theme.css : nav { /* Repeating background image */ background: url(http://weebtutorials.com/wp-content/uploads/2012/11/a.png); width:210px; margin:20px; } nav ul { /* Removes bullet points */ list-style:none; margin:0; padding:0; } nav ul li { /* Any child positioned absolutely will be positioned relative to this */ position:relative; } nav a { color:#e8e8e8; padding:12px 0px; /* Fill all available horizontal space */ display:block; /* Remove underline */ text-decoration:none; /* New CSS3 animations: apply transition to background property, taking 1s to change it */ transition:background 1s; -moz-transition:background 1s; -webkit-transition:background 1s; -o-transition:background 1s; font-family:tahoma; font-size:13px; text-transform:uppercase; padding-left:20px; } nav a:hover { /* RGBA background for transparancy: last number(0.05) is the transparency */ background: RGBA(255,255,255,0.05); color:#fff; } nav a:hover span { background: #7d2c41; transform:rotate(90deg); -moz-transform:rotate(90deg); -webkit-transform:rotate(90deg); } nav ul li:hover ul { display:block; } nav ul ul { position:absolute; left:210px; top:0; border-top:1px solid #e9e9e9; display:none; } nav ul ul li { width:200px; background:#f1f1f1; border:1px solid #e9e9e9; border-top:0; } nav ul ul li a { color:#a8a8a8; font-size:12px; text-transform:none; } nav ul … -
Paypal Button with £0 Option
I have a PayPal form which has an three options £5, £3 & £0. The button works if I choose either £5 or £3 but does not work with £0. Is there a way to capture when the "Pay" button is clicked and the option of £0 selected to redirect the user to a pre determined URL such as "bbc.co.uk"? Any help on this would be appreciated. Below is the form: <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="CUP9TLQ96MR28"> <table> <tr> <td><input type="hidden" name="on0" value="str8RED"></td> </tr> <tr> <td> <select name="os0"> <option value="Premium ->">Premium -> £5.00 GBP</option> <option value="Standard ->">Standard -> £3.00 GBP</option> <option value="Basic ----->">Basic -----> £0.00 GBP</option> </select> <input type="hidden" name="currency_code" value="GBP"> <input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"> </td> </tr> </table> -
Django server fail silent, don't response on any request
I have a project, based on Django. We add new bunch of apps (3-4), and server don't response on any request. **Log is clear.**It even don't log GET/POST requests. In browser I see: This site can’t be reached localhost refused to connect. I guess, that problem in new apps, so I removed it from INSTALLED_APPS, but result is the same. So I tried to find problem in settings.py, but result is still same. After that, I checked my ports by netstat and nmap, and I was stunned, because port 8000 is empty. root@artem-debian:/home/artem# nmap -sT -O localhost Starting Nmap 6.47 ( http://nmap.org ) at 2017-05-19 10:20 EEST Nmap scan report for localhost (127.0.0.1) Host is up (0.00018s latency). Other addresses for localhost (not scanned): 127.0.0.1 Not shown: 994 closed ports PORT STATE SERVICE 22/tcp open ssh 25/tcp open smtp 111/tcp open rpcbind 631/tcp open ipp 902/tcp open iss-realsecure 3306/tcp open mysql Device type: general purpose Running: Linux 3.X OS CPE: cpe:/o:linux:linux_kernel:3 OS details: Linux 3.7 - 3.15 Network Distance: 0 hops OS detection performed. Please report any incorrect results at http://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 2.76 seconds It really shocked me. My server, … -
validation of form embeded in base template django
I have a paginator in my base template, this pagination has a simple form that allows user to choose paginated page. But I do not know how to validate such form since it is in the base template which is not connected directly to any view. Right now if the user enters a number that exceeds the number of paginated pages it simply throws out 404. I guess the solution might involve context processor - but I do not understand how this works (and I could not find any straightforward explanation either). -
getting empty post request with Django1.10 + Nginx + Supervisor + Gunicorn
I'm making posts requests with curl using this, and even more simple than this: curl -u usr:pwd -H "Content-Type: multipart/form-data" -i --form "file=s=@/path/to/myfile/myfile.zip" -X POST http://midominio.co/api/mypostrequest/ but I'm always getting an empty body, this what I'm getting: { 'session': <django.contrib.sessions.backends.db.SessionStore object at 0x7f118e502b90>, '_post': <QueryDict: {}>, 'content_params': {'boundary': '------------------------axxxxxxxxx'}, '_post_parse_error': False, '_messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x7f118e502d90>, 'resolver_match': ResolverMatch(func=piston.resource.Resource, args=(), kwargs={}, url_name=None, app_names=[], namespaces=[]), 'GET': <QueryDict: {}>, '_stream': <django.core.handlers.wsgi.LimitedStream object at 0x7f118e502b50>, 'COOKIES': {}, '_files': <MultiValueDict: {}>, '_read_started': False, 'META': {'HTTP_AUTHORIZATION': 'Basic Y2FpbjpjYWlu', 'SERVER_SOFTWARE': 'gunicorn/19.7.1', 'SCRIPT_NAME': u'', 'REQUEST_METHOD': 'POST', 'PATH_INFO': u'/api/mypostrequest/', 'SERVER_PROTOCOL': 'HTTP/1.0', 'QUERY_STRING': '', 'CONTENT_LENGTH': '180', 'HTTP_USER_AGENT': 'curl/7.51.0', 'HTTP_CONNECTION': 'close', 'SERVER_NAME': 'midominio.co', 'REMOTE_ADDR': '', 'wsgi.url_scheme': 'http', 'SERVER_PORT': '80', 'wsgi.input': <gunicorn.http.body.Body object at 0x7f118e5029d0>, 'HTTP_HOST': 'midominio.co', 'wsgi.multithread': False, 'HTTP_ACCEPT': '*/*', 'wsgi.version': (1, 0), 'RAW_URI': '/api/mypostrequest/', 'wsgi.run_once': False, 'wsgi.errors': <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7f118e502950>, 'wsgi.multiprocess': True, 'gunicorn.socket': <socket._socketobject object at 0x7f118e4f6de0>, 'CONTENT_TYPE': 'multipart/form-data; boundary=------------------------axxxxxxxxx', 'HTTP_X_FORWARDED_FOR': '186.00.00.000', 'wsgi.file_wrapper': <class 'gunicorn.http.wsgi.FileWrapper'>}, 'environ': {'HTTP_AUTHORIZATION': 'Basic Y2FpbjpjYWlu', 'SERVER_SOFTWARE': 'gunicorn/19.7.1', 'SCRIPT_NAME': u'', 'REQUEST_METHOD': 'POST', 'PATH_INFO': u'/api/mypostrequest/', 'SERVER_PROTOCOL': 'HTTP/1.0', 'QUERY_STRING': '', 'CONTENT_LENGTH': '180', 'HTTP_USER_AGENT': 'curl/7.51.0', 'HTTP_CONNECTION': 'close', 'SERVER_NAME': 'midominio.co', 'REMOTE_ADDR': '', 'wsgi.url_scheme': 'http', 'SERVER_PORT': '80', 'wsgi.input': <gunicorn.http.body.Body object at 0x7f118e5029d0>, 'HTTP_HOST': 'midominio.co', 'wsgi.multithread': False, 'HTTP_ACCEPT': '*/*', 'wsgi.version': (1, 0), 'RAW_URI': '/api/mypostrequest/', 'wsgi.run_once': False, 'wsgi.errors': <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7f118e502950>, 'wsgi.multiprocess': … -
Python/Django datatable with pagination and checkboxes
I'm new with python/django and i have a problem with selecting all objects from other pages, i can only select them from current page. Wish someone to help me.. Heres my code: @login_required(login_url='/login/') def index(request): title = 'Tags' tag_list = Tags.objects.all() paginator = Paginator(tag_list, 10) page = request.GET.get('page') try: tags = paginator.page(page) except PageNotAnInteger: tags = paginator.page(1) except EmptyPage: tags = paginator.page(paginator.num_pages) return render(request, 'tag/index.html' , {'tags':tags, 'title':title}) js for checkboxes: <script language="JavaScript"> function toggle(source) { checkboxes = document.getElementsByName('selected'); for(var i=0, n=checkboxes.length;i<n;i++) { checkboxes[i].checked = source.checked; } } </script> index.html <form action="{% url 'tag:selected' %}" method="get"> <table id="dt" class="table table-bordered table-hover responsive" style="text-align:center;"> <thead> <tr> <th><input type="checkbox" onClick="toggle(this)"></th> <th></th> <td>Name</td> <td>Frequency</td> </tr> </thead> <tbody> {% for tags in tags %} <tr> <td><input type="checkbox" name="selected" value="{{ tags.id}}"></td> <td><a href="{% url 'tag:detail' tags.id %}"> <img src="{{ tags.tag_image.url }}" style="display:block; width: 80px; height:80px; margin:auto;"></a></td> <td>{{ tags.tag_name }}</td> <td>{{ tags.tag_frequency}}</td> </tr> {% endfor %} </tbody> </table><input class="btn btn-primary" style="float:right; margin-right:5%; margin-bottom:2%; margin-top:-3%; "type="submit" value="Submit"> </form> <div class="pagination"> <span class="step-links"> {% if tags.has_previous %} <a href="?page={{ tags.previous_page_number }}">previous</a> {% endif %} <span class="current"> Page {{ tags.number }} of {{ tags.paginator.num_pages }} </span> {% if tags.has_next %} <a href="?page={{ tags.next_page_number }}">next</a> {% endif %} </span> </div> -
django-rest-framework serializer different fields in multiple views
I am new at Django and couldn't find solution for my problem. The problem is to force specific serializer for include different amount of fields in case of utilizing different views. I would like to use 'id' field in my 1st view, and in 2nd view - 'id' and 'name' fields. Here is my model.py class Processing(models.Model): id = models.AutoField(primary_key=True) name = models.CharField() description = models.CharField() And here is my serializer.py class ProcessingSerializer(serializers.ModelSerializer): id = serializers.ModelField(model_field=Processing()._meta.get_field('id')) class Meta: model = Processing fields = ('id', 'name') Any help will be welcome. -
How to trigger Django Signals in sequence
I am firing a signal which has 3 different receivers. What I want to do is, I need to update a table Student in the signal update_student and later on I want to update his enrollment in update_student_enrollment. I want to update Enrollment after the Student has been updated. But my update enrollment receiver is triggering before the student updated. Sending the signal. Signal.send("student_updated", student_id=1, active=active) Receiver 1 @receiver(student_updated) def update_student(sender, **kwargs): Student.objects.update(active=0) # I am setting the student activtion to false. For simplycity I am not metioning the logic which is setting the student to inactive. print("Student Updated!") Receiver 2 @receiver(student_updated) def update_student_enrollment(sender, **kwargs): student=Student.objects.filter(student_id=1) if student.active=0: StudentEnrollment.objects.filter(student_id=1).update(active=0) Somehow my Receiver 2 is firing before the Receiver 1. -
Difficulty opening sql database
what i m trying to do is point to a relative path inside my django app. I do have to mention that test.py, forms.py and search.py are all in the same directory I have 2 .py files, the first one is this: Test.py import os import sqlite3 docs= os.path.abspath('..').rsplit("\\",1)[0] datab=(docs+ "\\BMS\\Database\\Database.db") datab.encode('unicode-escape') conn=sqlite3.connect(datab) This works fine, while i have the exact same code in search.py, inside a class which i import in forms.py which is part of django search.py import sqlite3 import os class SearchBy(object): docs= os.path.abspath('..').rsplit("\\",1)[0] datab=(docs+ "\\BMS\\Database\\Database.db") datab.encode('unicode-escape') conn=sqlite3.connect(datab) def get_countries(self): do something and finally forms.py from django import forms import sqlite3 from .search import SearchBy class searchForm(forms.Form): search_class=SearchBy() lista_tari=get_countries() country=forms.ChoiceField(choices=lista_tari, widget=forms.Select(), initial=0,required=True) I simply cannot uderstand why i am given this error: sqlite3.OperationalError: unable to open database file Under the circumstances that in the other file everything works fine. -
What is the best way of saving related model in django admin?
I have a model named Company: class Company(TimeStampedModel): company_id = models.CharField(max_length=20, unique=True) legal_name = models.CharField(max_length=200) trading_name = models.CharField(max_length=200, unique=True) # address address = models.CharField(max_length=200, null=True, blank=True) city = models.CharField(max_length=200, null=True, blank=True) state = models.CharField(max_length=200, null=True, blank=True) zipcode = models.CharField(max_length=200, null=True, blank=True) # contact details email = models.EmailField(max_length=200, null=True, blank=True) phone = models.CharField(max_length=200, null=True, blank=True) And other model is CompanyAttributes: class CompanyAttributes(TimeStampedModel): """ All attributes of company""" corporate = models.ForeignKey(Company) key = models.CharField(max_length=100) value = models.TextField(max_length=100) For a particular company I can have many attributes like billing address, CIN , GSTIN , Account number I displayed all the fields in a Single form by defining all the fields as form fields now I want to save all of them in one go . One way is overriding the save_model of ModelAdmin and save each attribute one by one. Is there a way by using save_related or some other method so that I can save all in one go. My model class CompanyModelForm(ModelForm): pan_number = CharField() cin_number = CharField() gstin_number = CharField() account_number = CharField() def __init__(self, *args, **kwargs): super(CorporateModelForm, self).__init__(*args, **kwargs) self.fields['zipcode'].required = True self.fields['email'].required = True self.fields['phone'].required = True self.fields['cin_number'].required = True self.fields['gstin_number'].required = True obj = kwargs.get('instance') if obj: … -
Database design for online food delivery system with book a table
I am thinking of developing an online food delivery system along with book a table/hall concept. There is only one competitor in the market. That is why i want to come up with user friendly complete feature package. I have designed a database but i want to take the idea of experts on how can i expand or simplify my database design. Please free to share your idea for the best database design. Here is what i have come up with Customer user(FK) first_name last_name phone_number email address liked_restaurant(M2M) Restaurant user(FK) name city place phone_number email website banner view lat lang speciality opening_time closing_time features(M2M) # like Breakfast, Lunch, Night Life etc status(open or closed) is_parking is_wifi timings(M2M) # sunday opening&closing time, monday opening&closing time, ... etc Category menu_category Menu restaurant(FK) category(FK) name price minimum_quantity available rating Order user(FK) order_id(PK) food_id(M2M) restaurant_id(FK) quantity total_price BookTable user(FK) restaurant(FK) quantity type - table/cabin/hall Review How should i structure my database with better design? Is there anything i have done mistake or missed? -
Editable email content for standard app users
I send emails using EmailMessage() where message = render_to_string("email/content.txt") content.txt looks for example like: Hi User Your payment for ${{ total_amount }} will process within 48 hours. I need to add the ability to edit this email content for my app users(with role='item_manager'). How can I do this? What is the best and recommended option? I think about standard text input with this content(instead of getting content from .txt file) but how to be sure that user provide correct variable name? -
Can't run Django template engine - Djano
from django import template t = template.Template("My name is {{ name }}.") c = template.Context({'name' : 'Yasmika'}) print(t.render(t)) I'm learning very basic of Python Django. When I'm trying to run Django template, Python interpreter gives me this error. How can I fix this? C:\Users\YasmikaSH\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/YasmikaSH/Desktop/lern_django/lern_django/test2.py Traceback (most recent call last): File "C:/Users/YasmikaSH/Desktop/lern_django/lern_django/test2.py", line 3, in <module> t = template.Template("My name is {{ name }}.") File "C:\Users\YasmikaSH\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py", line 184, in __init__ engine = Engine.get_default() File "C:\Users\YasmikaSH\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\engine.py", line 76, in get_default django_engines = [engine for engine in engines.all() File "C:\Users\YasmikaSH\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\utils.py", line 89, in all return [self[alias] for alias in self] File "C:\Users\YasmikaSH\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\utils.py", line 86, in __iter__ return iter(self.templates) File "C:\Users\YasmikaSH\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\utils\functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "C:\Users\YasmikaSH\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\utils.py", line 29, in templates self._templates = settings.TEMPLATES File "C:\Users\YasmikaSH\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__ self._setup(name) File "C:\Users\YasmikaSH\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\conf\__init__.py", line 39, in _setup % (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. -
403 Forbidden for S3 static files on Django app running on Heroku
This is a quite perplexing problem I have. First off, you can check out the website yourself with this link. As you can see, the stylesheet isn't loading from my S3 bucket, it's returning a 403 Forbidden error. Which doesn't make any sense because just to be sure before asking the question, I altered the permissions on the file and, all of it's parent directories to "Everyone can open/download". What's more is that everywhere else in the website, this problem doesn't occur. I don't even know where to start looking. Any advice is appreciated. Does anyone have any idea, why something like this would occur? Could it be a problem with the app itself? I don't think so, because the index works exactly as expected and it's in the same directory and loads the static files the same way. It may be a problem with Boto3? -
Tastypie allow data to be retreaved but not changed for some users
I want to limit write access for some of my users on my tastypie application. I was thinking of using DjangoAuthorization but to able to read data they need the tableName_change permissions which mean they can change some values. What is the easiest way do this. -
(Django/HTML/DHTMLX) HTML Table Column filters using DHTMLX dropdown checkbox and load from Django model
I'm trying to filter my HTML table column using DHTMLX dropdown checkbox filter, theres is 2 part for my question 1) I'm using a JSON file right now but how can I load my DHTMLX chekcbox fields from a Django model.py fields instead of a JSON file. 2) How can I link my table and my checkbox filter together so that whichever field I uncheck from my filter the respective column in my table is hide as well. Everyone helps is much appreciated Here's my code : model.py class Project(models.Model): name = models.CharField(max_length=100) position = models.CharField(max_length=100) department = models.CharField(max_length=100) def __str__(self): return self.name forms.py class ProjectForm(forms.ModelForm): class Meta: model = Project fields = ['Name', 'Position', 'Department'] views.py def index_view(request): context = { "table_list": Project.objects.all(), "title": "Table_List" } return render(request, 'index.html', context) url.py urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', index_view, name='index_view') fields.JSON { template: { input: "#position#" }, "options": [ {value: "ALL", text:"ALL", selected:true}, {value: "Name", text:"Name"}, {value: "Position", text:"Position"}, {value: "Department", text:"Department"}, ] } index.HTML <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <!--Drop-Down Checkbox--> <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet"> <link rel="stylesheet" href="http://cdn.dhtmlx.com/edge/dhtmlx.css" type="text/css"> <script src="http://cdn.dhtmlx.com/edge/dhtmlx.js" type="text/javascript"></script> </head> <h1>DHTMLX Filter</h1> <br> <br> </head> <body onload="doOnLoad();"> <h3>Checkboxes mode</h3> <div id="combo_zone"></div> <table class="myTable"> <thead> <tr> <th … -
How can I run docker python tests without pre-loading all local machines?
I am running Continuous Integration test with Docker and Django/Python. I run the following command in CircleCi: docker-compose -f dev.yml run django pytest So....all of the machines/services spin up and local/dev dependencies runs 12 steps to setup Docker. However, we don't need all of these steps to run tests, and would just like the necessary test steps to run. Is there any simple way to get this running? -
Generating a django HTML URL from a javascript function
I am using Django 1.10.6 and trying to generate a url from a javascript function in datatables under url.py I have an page called profile setup like: app_name = 'myapp' urlpatterns = [ url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileView.as_view(), name='profile'), ] In javascript I have a django query send data to a variable and the data is displayed on a table with name and id fields: var django_dat =[ { "id": 1, "name": "Jack Spicer", }, { "id":2, "name": "Ted Cracker", } { "id":3, "name": "Justin Rollin", } { "id":4, "name": "Boaty Boat", } ]; $(document).ready(function() { var table = $('#dattable').DataTable({ data: django_dat, columns: [{ 'data': null, 'render': function(data, type, row, meta) { //Django URL return '<a href={% url 'myapp:profile' 2 %}>' + data.name + '</a>';}}, { data: 'id' }] }); }); I am trying to change the URL so it link the name to a url like {% url 'myapp:profile' data.id %}. The above code is hardcoded to id=2 and works. Tried changing it to: return '<a href={% url 'myapp:profile' '+ data.id+ ' %}>' + data.name + '</a>' But that gave an No Reverse match error Reverse for 'profile' with arguments '('+ data.id+ ',)' and keyword arguments '{}' not found. 1 pattern(s) tried: … -
Develop board games with python that can be integrated with web application
I have thought of using tkinter library but It will create desktop application. I want to develop a game like chess that can be played on web application. can anyone guide me: 1) django will be required for development? 2) what should I use to save the state of user and then fetch it again when requested.