Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Changed JWT to OAuth2 and getting "Invalid token header. No credentials provided."
I decided to change my HTTP Authorization method from JWT to OAuth2. While testing my API with Postman, I'm getting same error for hours, "Invalid token header. No credentials provided." My header is Authorization: Bearer 416a444281fdcd6d2a344970eea0d47c22d01528 I don't see anything wrong in settings.py, but Do you see any? I commented out JWT setting just in case. INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'corsheaders', 'allauth', 'allauth.account', 'rest_auth.registration', 'rest_framework', 'rest_framework.authtoken', 'oauth2_provider', 'social_django', 'rest_framework_social_oauth2', 'rest_auth', ... 'allauth.socialaccount', 'storages', 'allauth.socialaccount.providers.facebook', ... ] # localhost:8000/ SITE_ID = 7 ACCOUNT_AUTHENTICATION_METHOD = 'username_email' ACCOUNT_EMAIL_VERIFICATION = 'none' SOCIALACCOUNT_EMAIL_VERIFICATION = 'none' REST_USE_JWT = False # for gmail EMAIL_USE_TLS = True EMAIL_HOST = ... EMAIL_HOST_USER = .. EMAIL_PORT = ... EMAIL_HOST_PASSWORD = ... EMAIL_BACKEND = ... DEFAULT_FROM_EMAIL = ... SERVER_EMAIL = ... LOGOUT_ON_PASSWORD_CHANGE = False OLD_PASSWORD_FIELD_ENABLED = True AUTHENTICATION_BACKENDS = ( # Oauth2 backends 'oauth2_provider.backends.OAuth2Backend', # Needed to login by username in Django admin, regardless of `allauth` 'django.contrib.auth.backends.ModelBackend', # `allauth` specific authentication methods, such as login by e-mail 'allauth.account.auth_backends.AuthenticationBackend', # Facebook OAuth2 'social_core.backends.facebook.FacebookAppOAuth2', 'social_core.backends.facebook.FacebookOAuth2', # django-rest-framework-social-oauth2 'rest_framework_social_oauth2.backends.DjangoOAuth2', ) MIDDLEWARE = [ # OAuth2 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'oauth2_provider.middleware.OAuth2TokenMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] CORS_ORIGIN_WHITELIST = ( '10.0.2.2', 'localhost' ) ROOT_URLCONF = ... TEMPLATES = [ … -
Django QuerySet/Manager filter employees by age from birthday
I am a beginner. I would like to get list employees have age > 25 and calculate the average age of employees. Currently, we need to get age from birthday (I have no idea about it ^^) . Please help me create sample QuerySet/Manager about it. Thanks all :)) My model: class Employee(models.Model): """"Employee model""" first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) birthday = models.DateField(max_length=8) -
Django model manager transaction and signal
# The model class UserManager(models.Manager): def create_user(self, temp_user_id): new_user = self.create(require data) # insert row to model B # The model manager class User(models.Model): # model fields objects = UserManager() # Post save signal handler def send_notification_to_user(sender, instance, created, **kwargs): # send sms notification to the newly created user signals.post_save.connect(send_notification_to_user, sender=User) # The view class UserView(APIView): def post(self, request, format=None): try: with transaction.atomic(): c_user = User.objects.create_user(request.data["temp_reg_id"]) return Response(status=status.HTTP_201_CREATED) except Exception as e: return Response(status=status.HTTP_400_BAD_REQUEST) In this scenario if a user registered then user get a sms. But here I'm running the model manager in transaction, so if somehow # insert row to model B instruction fails then all database will rollback. The problem is in this situation user will get the account creation sms, which is not true. How can I overcome this problem or which approach will be better? My English is not good, you can ask me for more explanation. -
django use spyne lib on apache server response no content
I have develop a webservice ,use spyne.protocol.soap.soap11. when running In django command (python manage runserver), it works as expected: 1.I can get wsdl file from $url?wsdl 2.call a webservice and get response but when deployed in apache server, it response $url?wsdl with status 200 OK but no content: "Connection →close Content-Length →0 Content-Type →text/xml; charset=utf-8 Date →Mon, 16 Oct 2017 02:22:08 GMT Server →Apache/2.2.15 (CentOS)" and I can also call a webservice, and the server do what i want(insert a data to database) but apache server response no content. note:all above running in the same machine, same python I have search in google and stackoverflow, but there is no similar questions. -
Django/AngularJS: How do I access my Python Context Items from my AngularJS Script
Good day SO! I am a beginner thats trying out a Django Project while using AngularJS for my frontend Firebase chat system. Here is a previous question that I asked regarding this project: Firebase/Angular: Messages not showing in HTML, but contain the message objects I know that it is not wise to use json variables on your html directly while using django/python, but it just so happens that my firebase chat module is using angularJS (and I do not know how to code this chat function in django..), and my angularJS code requires access to my Django's context querysets from View.py. Is there any way that I can either: Push json items into my HTML/Template the same way I push context information into my HTML/Template from Views.py and use it in my AngularJS Script? Access my Django/Python's data sets from Context from Views.py? Here is my AngularJS code for firebase: var app = angular.module('chatApp', ['firebase']); app.controller('ChatController', function($scope, $firebaseArray) { //I want to populate the crisis and sender variables with something from my context //from Views.py.. var crisis = "Crisis1"; var sender = "Sender1"; //Query var ref = firebase.database().ref().child(crisis).child('CMO-PMO'); $scope.messages = $firebaseArray(ref); $scope.send = function() { $scope.messages.$add({ sender: sender, message: $scope.messageText, … -
app.yaml username and password for django python on google app engine
How can i find the username, password and database for my app.yaml? "runtime: custom api_version: 1 vm: true env: flex entrypoint: gunicorn -b :$PORT main:app threadsafe: yes - url: .* script: test.wsgi.application runtime_config: python_version: 2 env_variables: # Replace user, password, database, and instance connection name with the values obtained # when configuring your Cloud SQL instance. SQLALCHEMY_DATABASE_URI: >- mysql+pymysql://USER:PASSWORD@/DATABASE?unix_socket=/cloudsql/intancesNAME beta_settings: cloud_sql_instances: intancesNAME " i am very new to GAE and django -
AttributeError at /notify/notify/ 'UserNotifications' object has no attribute 'user'
I am trying to make a notifications app. I have a middle that collects info about the action the user should be notified about and in the view that handles the action it automatically creates an instance in the UserNotification model. This is all working. Now, if a user's post gets liked by another user, that actions needs to be displayed on the notifications page. However, I obviously don't want any one use to be able to see every notification that is being created on the site, but rather only the notifications that are created by their posts. I am running into an issue with the view and filtering the notifications based on the current user. More specifically, I am getting this error: AttributeError at /notify/notify/ 'UserNotifications' object has no attribute 'user' With traceback: Traceback (most recent call last): File "/anaconda3/envs/dev/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner response = get_response(request) File "/anaconda3/envs/dev/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) File "/anaconda3/envs/dev/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/anaconda3/envs/dev/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view return self.dispatch(request, *args, **kwargs) File "/anaconda3/envs/dev/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 56, in dispatch return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs) File "/anaconda3/envs/dev/lib/python3.6/site-packages/django/views/generic/base.py", line 88, in dispatch return handler(request, *args, **kwargs) … -
Migration urls in app ...has no Migration class
Why when I try to run migration I get "Migration urls in app *** has no Migration class"? I just added new app and thats it. Have no idea what direction to look > C:\Users\PAPA\DEV\liberty\lib\site-packages\django\db\models\__init__.py:55: > RemovedInDjango19Warning: The utilities in django.db.models.loading > are deprecated in favor of the new application loading system. from > . import loading > > Traceback (most recent call last): File "manage.py", line 22, in > <module> > execute_from_command_line(sys.argv) File "C:\Users\PAPA\DEV\liberty\lib\site-packages\django\core\management\__init__.py", > line 338, in execute_from_command_line > utility.execute() File "C:\Users\PAPA\DEV\liberty\lib\site-packages\django\core\management\__init__.py", > line 330, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Users\PAPA\DEV\liberty\lib\site-packages\django\core\management\base.py", > line 390, in run_from_argv > self.execute(*args, **cmd_options) File "C:\Users\PAPA\DEV\liberty\lib\site-packages\django\core\management\base.py", > line 441, in execute > output = self.handle(*args, **options) File "C:\Users\PAPA\DEV\liberty\lib\site-packages\django\core\management\commands\makemigrations.py", > line 63, in handle > loader = MigrationLoader(None, ignore_no_migrations=True) File "C:\Users\PAPA\DEV\liberty\lib\site-packages\django\db\migrations\loader.py", > line 47, in __init__ > self.build_graph() File "C:\Users\PAPA\DEV\liberty\lib\site-packages\django\db\migrations\loader.py", > line 174, in build_graph > self.load_disk() File "C:\Users\PAPA\DEV\liberty\lib\site-packages\django\db\migrations\loader.py", > line 109, in load_disk > "Migration %s in app %s has no Migration class" % (migration_name, app_config.label) django.db.migrations.loader.BadMigrationError: > Migration urls in app expense has no Migration class -
Fixing this "Page not found (404)" error
I am attempting to access a page in my application but I keep getting this error : Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/nesting/Identity-nest/%7B%25%20url%20'nesting:Symptoms_nest_list'%7D Using the URLconf defined in Identity.urls, Django tried these URL patterns, in this order: ^admin/ ^Identity/ ^nesting/ ^$[name='nesting'] ^nesting/ ^Identity-nest/$[name='Identity_nest_list'] ^nesting/ ^Symptoms-document/$[name='Symptoms_nest_list'] ^$ [name='login_redirect'] The current URL, nesting/Identity-nest/{% url 'nesting:Symptoms_nest_list'}, didn't match any of these. This is my main urls.py from django.conf.urls import url, include from django.contrib import admin from Identity import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^Identity/', include('Identities.urls', namespace = 'Identities')), url(r'^nesting/', include('nesting.urls', namespace = 'nesting')), url(r'^$', views.login_redirect, name = 'login_redirect'), ] This is my nesting urls.py from django.conf.urls import url from nesting.views import Identity_view, Identity_nest_list_view, Symptoms_document_view from . import views urlpatterns = [ url(r'^$', Identity_view.as_view(), name = 'nesting'), url(r'^Identity-nest/$', Identity_nest_list_view.as_view(), name = 'Identity_nest_list'), url(r'^Symptoms-document/$', Symptoms_document_view.as_view(), name = 'Symptoms_nest_list') ] This is my views.py class Symptoms_document_view(TemplateView): model = Symptoms template_name = 'nesting/Symptoms_list.html' def get(self, request): form = Symptom_Form() Symptoms_desc = Symptoms.objects.all() var = {'form':form, 'Symptoms_desc':Symptoms_desc} return render(request, self.template_name, var) def post(self, request): form = Symptom_Form(request.POST or None) Symptom_content = None if form.is_valid(): Symptoms_description = form.save(commit = False) Symptoms_description.user = request.user Symptoms_description.save() Symptoms_content = form.cleaned_data['Symptoms_description'] form = Symptom_Form() redirect('nesting:nesting') var = {'form': … -
How to initialize django objects automatically for the first time?
This is my first django application and I looked all over the place to find an answer, to no avail. I created my models and I know need to to initialize the values to one of the classes. I could do it using the admin page, one by one, but I want anyone using my application to be able to just load the application for the first time to have all the correct objects (and associated records in the database) to be created automatically. Please help -
Django: how to create a record that contains one or more items from a different db tables
I want to make a simple ticket system. I have 3 tables : Ticket, Responsible and Services .I also have the views that create, update and delete data to all 3 tables. what I am having problems is creating a view that creates the main ticket. My 3 tables are Ticket, Services and Responsible. my ticket can only have one responsible person and my ticket need to have one or more services. I'm lost on how to select multiple services to a ticket my models looks like this: from django.db import models from django.core.urlresolvers import reverse # Create your models here. class Servicios(models.Model): servicio = models.CharField(max_length=250) precio = models.FloatField() class Doctor(models.Model): nombre = models.CharField(max_length=250) porcentaje = models.FloatField() class Ticket(models.Model): fecha = models.DateTimeField(auto_now_add=True) servicio = models.ForeignKey(Servicios) doctor = models.ForeignKey(Doctor) cantidad = models.IntegerField() p_unitario = models.FloatField() total = models.FloatField() def get_absolute_url(self): return reverse('Main:get-list') -
I can't open manage.py
On the command prompt, (Windows 10) I created a virtual environment, I then created a new project, I installed django in the virtual environment using pip. Then decided to run the command python manage.py runserver To run djangos web server, This returned with "...can't open file 'manage.py': [Errno 2] No such file or directory" I did see a similar question to this on this platform but it seems to only apply to those using linux. Where answers specify to use the ls command, which is not applicable on Windows command prompt. I have tried this multiple times but i just can't open manage.py -
Django creates migration files after each 'makemigrations' because of dictionary?
I've noticed strange things in my Django project. Each time I run python manage.py makemigrations command new migration file for my app called notifications is created. I did zero changes to the model, but the new migration file is created. I can run makemigrations command N number of times and N number of migration files will be created. The model looks as following: from django.db import models from django.db.models.fields import EmailField class EmailLog(models.Model): email = models.EmailField(max_length=70, null=False) subject = models.CharField(max_length=255, null=False) html_body = models.TextField(null=False) sent_choices = { ('OK', 'Sent'), ('KO', 'Not sent'), ('KK', 'Unexpected problems') } status = models.CharField(max_length=2, choices=sent_choices, null=False, default='KO') sent_log = models.TextField(null=True) sent_date = models.DateTimeField(auto_now_add=True, null=False) Each migration just swaps the position of sent_choices field. that's all! Is it because dictionaries in Python have random order? How do I avoid it? -
nginx unix:/webapps/myproject/run/gunicorn.sock failed (13: Permission denied) while connecting to upstream
Want to do work assembly: django, nginx, gunicorn, supervisor, centos 7. Work perfect, but I have one problem and one error in browser - "502 Bad Gateway nginx/1.10.2". nginx-error.log unix:/webapps/myproject/run/gunicorn.sock failed (13: Permission denied) while connecting to upstream, client: 192.168.4.33, server: 192.168.4.39, request: "GET / HTTP/1.1", upstream: "http://unix:/webapps/myproject/run/gunicorn.sock:/", host: "192.168.4.39" Haven`t idia how to fix it. Had tried configure selinux, give permissions, change users and some anything else, but it is did not help, I do not have enough knowledge. /etc/nginx/conf.d/myproject.conf server { listen 80; server_name 192.168.4.39; location = /favicon.ico { access_log off; log_not_found off; } client_max_body_size 2G; access_log /webapps/myproject/logs/nginx-access.log; error_log /webapps/myproject/logs/nginx-error.log; location /static/ { root /webapps/myproject/; } location /media/ { alias /webapps/myproject/media/; } location / { # include proxy_params; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; # proxy_pass http://127.0.0.1:8000; proxy_pass http://unix:/webapps/myproject/run/gunicorn.sock; } } gunicorn_start.bash #!/bin/bash NAME="myproject" # Name of the application DJANGODIR=/webapps/myproject/ # Django project directory SOCKFILE=/webapps/myproject/run/gunicorn.sock # we will communicte using this unix socket USER=myproject # the user to run as GROUP=webapps # the group to run as NUM_WORKERS=3 # how many worker processes should Gunicorn spawn DJANGO_SETTINGS_MODULE=myproject.settings # which settings file should Django use DJANGO_WSGI_MODULE=myproject.wsgi # WSGI module name echo "Starting $NAME … -
Django - field of language choices
I want to let user choose from languages they speak. Is there a Django built in list of languages or should I get list of languages from other source? For now: class UserProfile(models.Model): languages = models.ManyToManyField(Language) class Language(models.Model): shortcut ... name ... The languages field should only be able to list all languages user can speak. -
django + gunicorn + nginx: Browser refreshes toggling between PRE/POST dynamic content change
Below are the nginx.conf and gunicorn.start.sh files that I use for the Django application that I'm running (which, by the way, I didn't write). When I make any one-time change to dynamic content, then repeatedly refresh the browser, the rendered content switches/flaps variously between PRE and POST changes made. But it should just update once, and never again. The only thing that momentarily fixes the issue is restarting gunicorn: myapp$ sudo supervisorctl restart gunicorn But this only works until the next change to dynamic content. No good. I've tried numerous browsers, and it happens even when I clear their caches. Makes no difference. I also temporarily tried uWSGI instead of gunicorn (just to see), and the same issue occurs. A tail -f gunicorn.access.log during browser refreshes shows HTTP statuses that vary between 200 (content was downloaded) and 304 (you already have the content; redirecting you to your local cache). But dynamic content shouldn't be cached. Note that when running the application using the development server, like this: myapp$ python manage.py runserver --settings live 0.0.0.0:8080 the issue doesn't occur; but neither does this use nginx nor gunicorn. Any ideas? I've tried everything I know, but don't know what is causing this … -
Django + mod_wsgi Fatal Python Error: Py_Initialize: No module named Encodings
I am attempting to get a website to load within a web browser using Django + mod_wsgi and apache. I have exactly the same problem as in This Question Here, but the solution found there does not work in my case. Here is my httpd-vhosts.conf setup: WSGIDaemonProcess binshellpress.com python-home=/usr/local/docs/binshellpress-production/virtpy/ python-path=/usr/local/docs/binshellpress-production/virtpy/lib/python3.6/ WSGIProcessGroup binshellpress.com WSGIApplicationGroup %{GLOBAL} <VirtualHost *:80> ServerAdmin webmaster@binshellpress.com DocumentRoot "/usr/local/docs/binshellpress-production/root" ServerName binshellpress.com ServerAlias www.binshellpress.com ErrorLog "/var/log/httpd/bsp-error_log" CustomLog "/var/log/httpd/bsp-access_log" common Alias /robots.txt /usr/local/docs/binshellpress-production/static/robots.txt Alias /favicon.ico /usr/local/docs/binshellpress-production/static/favicon.ico Alias /media/ /usr/local/docs/binshellpress-production/media Alias /static/ /usr/local/docs/binshellpress-production/static <Directory /usr/local/docs/binshellpress-production/static> Require all granted </Directory> <Directory /usr/local/docs/binshellpress-production/media> Require all granted </Directory> WSGIScriptAlias / /usr/local/docs/binshellpress-production/binshellpress/wsgi.py process-group=binshellpress.com <Directory /usr/local/docs/binshellpress-production/binshellpress> <Files wsgi.py> Require all granted </Files> </Directory> </Virtualhost> I have a virtual environment set up at /usr/local/docs/binshellpress-production/virtpy. I have rebuilt mod_wsgi to explicitly use that virtual environment. I have performed the permissions modifications as described in the answer to This Question No change. I am desperate. I have been searching up and down. I can't figure out what to do. Please, help me. I beg you. Thank you, for anything, thank, just please, help me, thank you. -
Request google app engine
I do a http request with module requests in django (python 3), import requests url = 'https://www.google.es' r = requests.get(url) str = str(r.content) and It work right in localhost, but when I deploy in Google App Engine, It return a "('Connection aborted.', error(104, 'connection reset by peer'))", I deploy in a flex enviroment. I read than it not necessary change for urlfetch module. -
Unresponsive django-bootstrap3-datetimepicker (not showing calendar)
As a beginner I often struggle with understanding the connections between Python-Django, html, javascript and css. The problem at hand is this: I'm trying to implement DateTimePicker widget from django-bootstrap3-datetimepicker-2. Since this library does not include js/css assets, I started by implementing datetimepicker without backend involvement just to see if I loaded all static files etc. correctly. Thus, I added this example to html template: <div class="container"> <div class="row"> <div class="col-sm-6"> <div class="form-group"> <div class="input-group date" id="datetimepicker1"> <input type="text" class="form-control"> <span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> </div> </div> <script type="text/javascript"> $(function () { $('#datetimepicker1').datetimepicker(); }); </script> </div> </div> Everything worked as intended, so I tried to implement datetimepicker as a widget from django forms: class FooForm(forms.Form): pick_a_date = forms.DateTimeField( widget=DateTimePicker(options={ "format": "YYYY-MM-DD", "pickTime": False} )) I also wanted to benefit from form wizard (namely SessionWizardView from formtools.wizard), so I output the above mentioned form into html like this: <form action="" method="post" role="form">{% csrf_token %} <table> {{ wizard.management_form }} {% if wizard.form.forms %} {{ wizard.form.management_form }} {% for form in wizard.form.forms %} {{ form }} {% endfor %} {% else %} {{ wizard.form }} {% endif %} </table> However, the widget is not responsive (the calendar window isn't showing, the … -
django can't find my choiceField on fields
I have my class: from django import forms from .models import Donator class DonatorForm(forms.ModelForm): BLOOD_CHOICES = ( ('A-','A-'), ('A+','A+'), ('B-','B-'), ('B+','B+'), ('AB-','AB-'), ('AB+','AB+'), ('O-','O-'), ('O+','O+'), ('TODOS','TODOS') ) SITUATION_CHOICES = ( ('Sem Problemas','Sem Problemas'), ('Problemas Momentâneos','Problemas Momentâneos'), ('Problemas Graves', 'Problemas Graves') ) class Meta: model = Donator fields = ('name', 'age', 'email','phone', forms.ChoiceField(choices = SITUATION_CHOICES, required=True, label = "Situacao do Doador"), 'bloodType', 'observation') I receive: NameError: name 'SITUATION_CHOICES' is not defined How could I correctly mention my fieldCHoices to appear a dropdown on the Form? -
How to use django login_required method
$ class HomePage(TemplateView): template_name = 'obs/homepage.html' I want to make this view accessible to only logged in users. How can i do that? i've seen django documentation but it was for functions. -
Creating / storing a form preview with Django forms and cart
I've never had to do this before and I'm wondering if I'm on the right track / this is the standard way to do something of this nature. I was going to use Django formtools FormPreview but it doesn' handle files (They can upload various images)... So, rolling my own solution or trying to. Currently I'm using a form wizard with model forms and everything validates / saves fine. I now want to add in a form preview, before purchasing the item they create with the form, and I've thought about doing the following: Save it to the database but mark it as not paid / inactive. On the form preview page grab the id (from pk in url) and display it. They have the option to go back and edit (update view) and / or pay. Using this route it's really easy to update and grab the data for viewing whether they wish to go back or forward. Similarly, if they add multiple items in their cart I can just display these items by grabbing the pk's from the DB rather than trying to handle a ton of session data. If they remove the item -> delete the row … -
Django UpdateView - get initial data from many-to-many field and add them when saving form
I'm using Django class based generic view. In my models.py I have a model called MyModel with many-to-many field called m2m. I have multiple groups of users they can edit the m2m field. Each group of users can only see and add their portion to the field - using get_form to set what they can see in the m2m field. The problem I'm having is that when one user enter his record it will delete the initial records in the m2m field. I need to somehow get the initial values from the m2m field save them and then add them to the new ones when the form is submitted. Here is my views.py: class MyModelUpdate(UpdateView): model = MyModel fields = ['m2m'] def get_initial(self): return initials def get_form(self, form_class=None): form = super(MyModelUpdate, self).get_form(form_class) form.fields["m2m"].queryset = DiffModel.objects.filter(user = self.request.user) return form def form_valid(self, form): form.instance.m2m.add( ??? add the initial values) return super(MyModelUpdate, self).form_valid(form) def get_success_url(self): ... -
django app deploy to google app engine
I am trying to deploy my django project on google app engine. When I 'gcloud app deploy' everything looks like it is going well except it takes a really long time. Then I get the message: 'ERROR: (gcloud.app.deploy) Error Response: [4] Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.' I checked my acitivity log in google cloud and i have the error: " STATIC_ADDRESSES quota limit reached " This is my first django project and first time on google app engine. How can I get this thing up? -
How to start building a django website with postgres nginx and gunicorn on separate machines?
I searched all over the internet and I guess I'm lost, Please I want a detailed answer here. I know how to make all three of these things(gunicorn, Nginx, and Postgres) work on the same machine but what if I wanna have all of them on the different/individual machine. Let's say I got 3 behemoth powerful machines capable of handling anything but the real question in my mind is where do I start. how can I connect all three of these together? what if I wanna add more storage? How do I connect multiple database machines together I'm sorry but I'm pretty new in networking and it's really crucial for me to understand this because if I don't my mind won't allow me to go ahead with the process.