Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Display my response errors in span with their respective fields
In this html file i define form and span fields for displaying respective fields errors.How i show my response errors in span with respective fields. Please help How i show my response errors in span with respective fields. Please help This my response of django view when i submit form: {"result": "error", "message": {"username": ["Please fill the username"], "first_name": ["Please fill the first name"], "last_name": ["Please fill the last name"], "email": ["Please fill the email"], "password": ["Please fill the password"], "password2": ["Please fill the confirm password"]}} How i show my response errors in span with respective fields. Please help My html file: In this html file i define form and span fields for displaying respective fields errors. How i show my response errors in span with respective fields. Please help How i show my response errors in span with respective fields. Please help How i show my response errors in span with respective fields. Please help {% block body %} <html> <head> </head> <body> <form id="wrapper"> // This my form <div id="div2"> <h1>Create an account</h1> <li> <input type="text" placeholder="Username" id="username" name="username"> // This my input <input type="text" placeholder="First Name" id="first_name" name="first_name"> </li> <span style="color: red" name="username"></span> <span style="color: red" name="first_name"></span> … -
How to create Scheduled skype online meeting link programatically by python/django?
I want to create skype meeting link like "join.skype.com/YHeJdxncAImN" programatically in python , that we get when we click "create a free meeting " button in https://www.skype.com/en/free-conference-call/ . After getting the link i'll send it through email to user to connect the meeting ...I am very new in django . Please help me.. Thank you in advance ... -
How to make single user for multiple Django projects?
I have created a Django project in which I have created too many apps. Due to too many apps, my current deployed server getting slower. To solve this problem and for the new extra upcoming apps, I want to create a new Django project and will deploy it on the other server but I don't have an idea how to use all old project apps features as well as all users here I found django-sso answer in github question regarding SSO find one article here and followed, used Django-Simple SSO but this article flow is not working. django-cas-server this library not follow django3+ is there any better way? I didn't find any goood article regarding django-SSO. Anyone help or suggestion will be more valuable for me and for Django SSO... -
How to add samesite none option in django settings file
I used Django 2.0.2 version. I tried to process google authentication in Django project. I got the token but I will pass URL and token. it return 404 error. I need to add samesite='none' in Django settings project. Where to add I don't know and I tried to add many ways but still it's throwing 404 error. How to fix it. Settings.py MIDDLEWARE = [ 'django_cookies_samesite.middleware.CookiesSameSite', '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', ] So, I added samesite.middleware.CookiesSameSite middleware. but still I facing this warning A cookie associated with a cross-site resource at http://stats.XXXX.com/ was set without the SameSite attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details How to fix it -
Expected table or queryset, not str
I am trying to render a table using django-tables2, but I get this error message: Expected table or queryset, not str views.py: def getKpiTableCsd(request, report_id): template = loader.get_template('kpi/confirm_kpi_csd.html') report = get_object_or_404(KpiMembersCsd, id=report_id) context = RequestContext(request, {'report': report}) table_context = KpiMembersCsdTable(KpiMembersCsd.objects.filter( id=report_id)) # creating table object not string return HttpResponse(template.render(context.flatten()), {'table': table_context}) tables.py: import django_tables2 as tables import kpi.models class KpiMembersCsdTable(tables.Table): class Meta: model = kpi.models.KpiMembersCsd Traceback: File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view return view_func(request, *args, **kwargs) File "/home/flex/work/02_dolasilla/dolasilla_seite/kpi/views.py", line 32, in getKpiTableCsd return HttpResponse(template.render(context.flatten()), File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render return self.template.render(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/base.py", line 171, in render return self._render(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/base.py", line 163, in _render return self.nodelist.render(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated return self.render(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render return compiled_parent._render(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/base.py", line 163, in _render return self.nodelist.render(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated return self.render(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render result = block.nodelist.render(context) File "/home/flex/work/02_dolasilla/dolasilla/lib/python3.7/site-packages/django/template/base.py", line … -
why posts are not shown in home page?
when I add a post in the admin panel, the posts are not shown on the home page of the app. it only shows spaces of the post but couldn't show writeup of the post on the home page. views.py from django.shortcuts import render,HttpResponseRedirect from django.contrib import messages from django.http import HttpResponse from .forms import SignUpForm, LoginForm from django.contrib.auth import authenticate, login, logout from .models import Post # Create your views here. # home def home(request): posts = Post.objects.all() return render(request, 'blog/home.html',{'posts':posts}) home.html {% extends 'blog/base.html' %} {% load static %} {% block content %} <div class="col-sm-10"> <h3 class="text-white my-5">Home Page</h3> {% for post in posts %} <div class="jumbotron jumbotron-fluid jumbo-colour"> <div class="container"> <h1 class="display-4 font-weight-bold">{{posts.title}}</h1> <p class="lead">{{posts.desc}}</p> </div> </div> {% endfor %} </div> {% endblock content %} models.py from django.db import models # Create your models here. class Post(models.Model): title = models.CharField(max_length=150) desc = models.TextField() -
Django Gateway Timeout running on IIS
I am running a Django app on a windows 10 machine with IIS web server. The application based on user command starts a selenium instance and try to collect some data from third party sites. The problem is that when the collecting data gets long time, actually more than 30s i get a 504 Gateway Timeout at the client. I searched across the web and find some parameters to set including: ARR timeout application pool idle timeout Default website Connection timeout adding following parameters to the applicationHost.config file: <application fullPath="..." arguments="...\wfastcgi.py" signalBeforeTerminateSeconds="60" idleTimeout="900" activityTimeout="180" requestTimeout="10000" /> But, any of them helped and the 504 again on 30s. -
What is the differences between __date__range and __range for writing django queries?
I am getting different datasets when using __date__range["2019-04-01","2019-04-30"] and for __range["2019-04-30"] -
TypeError: Object of type 'TopicSerializer' is not JSON serializable Django
Hi All I faced this issue while getting API response. I am using django==2.1.7. Below I am adding my code snippet models.py The model contains topic names(en,bn), taglist(string), and Bucket_id or topic_id class Topics(models.Model): id = models.AutoField(primary_key=True) name_en = models.CharField(max_length=70, blank=False, default='') name_bn = models.CharField(max_length=70, blank=False, default='') tags = models.TextField(blank=False, default='') bucket_id = models.IntegerField() def set_tags(self, x): self.tags = json.dumps(x) def get_tags(self): return json.loads(self.tags) class Meta: managed = True db_table = 'follow_topics' serialize.py TopicSeializer used for JSON serialize the model from rest_framework import serializers from .models import Topics class TopicSerializer(serializers.ModelSerializer): class Meta: model = Topics fields = ['name_en','name_bn','tags', 'bucket_id'] views.py get_topic function gives me the list of the topic from the model @api_view(('GET',)) def get_topics(requests): topic_id = requests.GET.get('topic_id', None) post_data = Topics.objects.filter(bucket_id=topic_id).first() serialize_data = TopicSerializer(post_data, many=True) return Response({"status": "success", "data": serialize_data}) I got serializable error. This error looks frustrating for me. Please help me share some useful resource or way that I can fix this error Environment: Request Method: GET Request URL: http://127.0.0.1:8000/feed/v1/get_topics?topic_id=2 Django Version: 2.1.7 Python Version: 3.6.8 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'debug_toolbar', 'rest_framework', 'feedv1'] Installed Middleware: ['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', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.BrokenLinkEmailsMiddleware', 'django.middleware.common.CommonMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware'] Traceback: File "/Users/luo/tutorial-env/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 34. response … -
{% csrf_token %} is not working in django
Template includes just only html forms and it says CSRF token missing or incorrect. template: <form method='POST'> {% csrf_token %} <div class='row'> <div class='col'> <input value={{ option1 }} type='submit' class="btn btn-primary btn-lg btn-block button" name='option'/> </div> <div class='col'> <input value={{ option2 }} type='submit' class="btn btn-primary btn-lg btn-block button" name='option'/> </div> </div> </form> Code for views.py def QuestionAnswer(request, user_id, user, question_id): user = User.objects.get(pk=user_id) question = Question.objects.all().filter(user=user) option = Choices.objects.all().filter(question = question[0]) return render(request, 'quiz/QuestionAnswer.html', { 'question':question[0].question, 'option1':option[0], 'option2':option[1], }) -
Error: Could not read from 'src\pip\_vendor\requests\cookies.py': Bad file descriptor
I was trying to create a new django project using pycharm but it keeps saying bad file descriptor. I completely uninstalled python and pycharm and reinstalled several times but still it did not work. I also noticed that the python scripts file is empty where there should be a easy_install and pip after reinstallation. running install running bdist_egg running egg_info writing src\pip.egg-info\PKG-INFO writing dependency_links to src\pip.egg-info\dependency_links.txt writing entry points to src\pip.egg-info\entry_points.txt writing top-level names to src\pip.egg-info\top_level.txt reading manifest file 'src\pip.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'src\pip.egg-info\SOURCES.txt' installing library code to build\bdist.win-amd64\egg running install_lib running build_py creating build creating build\lib creating build\lib\pip copying src\pip\__init__.py -> build\lib\pip copying src\pip\__main__.py -> build\lib\pip creating build\lib\pip\_internal copying src\pip\_internal\build_env.py -> build\lib\pip\_internal copying src\pip\_internal\cache.py -> build\lib\pip\_internal copying src\pip\_internal\configuration.py -> build\lib\pip\_internal copying src\pip\_internal\download.py -> build\lib\pip\_internal copying src\pip\_internal\exceptions.py -> build\lib\pip\_internal copying src\pip\_internal\index.py -> build\lib\pip\_internal copying src\pip\_internal\locations.py -> build\lib\pip\_internal copying src\pip\_internal\pep425tags.py -> build\lib\pip\_internal copying src\pip\_internal\pyproject.py -> build\lib\pip\_internal copying src\pip\_internal\resolve.py -> build\lib\pip\_internal copying src\pip\_internal\wheel.py -> build\lib\pip\_internal copying src\pip\_internal\__init__.py -> build\lib\pip\_internal creating build\lib\pip\_vendor copying src\pip\_vendor\appdirs.py -> build\lib\pip\_vendor copying src\pip\_vendor\distro.py -> build\lib\pip\_vendor copying src\pip\_vendor\ipaddress.py -> build\lib\pip\_vendor copying src\pip\_vendor\pyparsing.py -> build\lib\pip\_vendor copying src\pip\_vendor\retrying.py -> build\lib\pip\_vendor copying src\pip\_vendor\six.py -> build\lib\pip\_vendor copying src\pip\_vendor\__init__.py -> build\lib\pip\_vendor creating build\lib\pip\_internal\cli copying src\pip\_internal\cli\autocompletion.py -> build\lib\pip\_internal\cli copying src\pip\_internal\cli\base_command.py -> … -
makemigrations take duplicate entries django
I have created 2 models in Django Rest Framework Python. 1 model is joined to other model using foreign Key. The problem I am facing is even if I don't make any changes, makemigrations would still consider the model fields as changed. **This is model 1 ** class ProfessionalStepServiceData(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE,blank=True, null=True) profession = models.ForeignKey(Profession, on_delete=models.CASCADE,blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) is_deleted = models.BooleanField(default = False, help_text="activate/deactivate skills") service_description = models.TextField(max_length=500,blank=True,null=True) def __str__(self): return "{}-{}".format(self.profession, self.user) class Meta: verbose_name_plural = "Step Service Data" db_table = 'professional_StepData' This is model 2 class Profession(models.Model): professionName = models.CharField(max_length=200) created_at = models.DateTimeField(auto_now_add=True,blank=True,null=True) def __str__(self): return "{}".format(self.professionName) class Meta: verbose_name_plural = 'Static Profession' db_table = 'StaticProfession' now even if I don't make any changes to ProfessionalStepServiceData, It would still get added on makemigrations stating that profession Field in ProfessionalStepServiceData has been altered. Is this a bug or I am messing with something? -
Not Displaying error message in Django Admin?
Whenever i try to add project of same name it leads to IntegrityError at /admin instead there should be an Error message on Django admin that "This project already exists". Also i have two users. So same user cannot have project of same name and different users can have project of same name. Please let me know how to fix this. class Project(models.Model): name = models.CharField(max_length=200) added_by = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True, default=None) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: unique_together = (("name", "added_by"),) -
while creating user for my postgreSQL database. I get error su : The term 'su' is not recognized
I run the following command in my windows powerShell su postgres su : The term 'su' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 su postgres ~~ CategoryInfo : ObjectNotFound: (su:String) [], CommandNotFoundException FullyQualifiedErrorId : CommandNotFoundException -
display two objects by for loop django
my template has a timeline structure.. so 1 object is left aligned and other is right aligned .. i want to display them alternatively within a for loop.. content from same model but alignments of divs are Diffrent.. <ul class="timeline"> <li class="timeline-right"> <div class="timeline-badge"> <i class="fa fa-calendar"></i> <p class="date-inverted wow slideInLeft">{{Experience.first.FromDate}} -{{Experience.first.ToDate}}</p> </div><!-- end timeline-badge --> <div class="timeline-panel wow slideInRight"> <div class="experience-content"> <h4>{{Experience.first.Designation}}</h4> <h5>{{Experience.first.Department}}</h5> <p>{{Experience.first.ShortNote}}</p> </div> </div><!--end timeline-panel --> </li><!-- end timeline-right --> <li class="timeline-left"> <div class="timeline-badge"> <i class="fa fa-calendar"></i> <p class="date wow slideInRight">Oct 2015 - Nov 2016</p> </div><!-- end timeline-badge --> <div class="timeline-panel wow slideInLeft"> <div class="experience-content"> <h4>MGS PVT. LTD.</h4> <h5>Senior Designer </h5> <p>The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks.</p> </div> </div><!-- end timeline-panel --> </li><!-- end timeline-left --> models. py class Experience(models.Model): Designation = models.CharField(max_length=150) Department = models.CharField(max_length=150,default='my dept') Organisation =models.CharField(max_length=150) ShortNote = models.CharField(max_length=200) FromDate = models.DateField( default=datetime.date.today) ToDate = models.DateField(default=datetime.date.today) def __str__(self): return self.Designation -
Save incoming data from a webhook
{'event_type': 'shipment.label.created', 'resource_type': 'shipment', 'resource_id': 'ESTEST00000', 'label':{'easyship_shipment_id': 'ESTEST00000', 'platform_order_number': '#100001', 'status': 'success', 'label_url'}} I'm trying to link easyship webhook with my django project , I'm successfully recieivng the above data from easyship, However I would like to save status into my shipment models easyhip_satatus field , where the shipment_id of an object is equal to easyship_shipment_id. My def post function is not working. models.py Shipment(models.Model): shipment_id = models.CharField(max_length =100, null=True, blank=True) easypost_status = models.CharField(max_length =100, null=True, blank=True) def post(self,request): print(request.data) order = get_or_404(Order, shipment_id=request.data['label']['easyship_shipment_id']) order.objects.filter(shipment_id=order).update(easypost_status = ['event_type']['status'] return Response(request.data) -
Django connect mysql issue
I am connecting my mysql database to django.While migrating or running django app it shows following error: mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) My database is accessible configuration is also correct in my config file.As when i type wrong database name it shows no database found. [client] database = vs4 user = newuserq password = tooq default-character-set = utf8 How to fix this error and why in this error it is asking for 'root' user, i have written 'newuser' user in my django config. -
Is django-seeder also use when model have foreign key?
I'm trying to use django-seeder in language model when create profile, models: class Profile(models.Model): name = models.CharField(max_length = 255) email = models.EmailField(unique=True) phone_no = models.CharField(max_length=10) def __str__(self): return self.name class Language(models.Model): user = models.ForeignKey(Profile, on_delete = models.CASCADE) language = models.CharField(max_length=255) proficiency = models.CharField(max_length=32,choices=PROFICIENCY) def __str__(self): return self.language when I create Profile, I need to create Language objects. -
What is the best Workflow for Updating a Web App
I'm pretty new at this but I recently deployed my first web application using Django, Postgres, Nginx, and Gunicorn on Digital Ocean. I went to make some updates and ran sudo service gunicorn restart to see the changes. I wiped my entire Database. I obviously need to work on setting up a better workflow for deploying to production. Does anyone have any suggestions? What are some best practises when re-deploying a Django App with a Postgres DB? I've read some articles about backing up my DB (which I'm definitely going to be doing in future), but what else can be done to ensure a seem-less transition? -
.dockerignore: some files are ignored, some are not
The Problem Hi I'm new to Docker. I want to ignore some files and directories using .dockerignore in my Django project. In the beginning, no files were ignored , then I searched in stackoverflow and found that its because of the volumes in docker-compose.yml, so I commented it out. But now some of the files and directories are getting ignored but some are not. I went through a lot of questions but couldn't find any solution. Project structure -src --coreapp ---migrations ---__init__.py ---__pycache__ ---admin.py ---apps.py ---models.py ---tests.py ---views.py ---tests.py --UserApp ---migrations ---__init__.py ---__pycache__ ---admin.py ---apps.py ---models.py ---tests.py ---views.py ---tests.py --admin.json --db.sqlite3 --manage.py -.dockerignore -.gitignore -docker-compose.yml -Dockerfile -Procfile -README.md -requirements.txt -runtime.txt Dockerfile FROM python:3.7 ENV PYTHONUNBUFFERED 1 COPY ./requirements.txt /code/requirements.txt RUN pip install -r /code/requirements.txt COPY . /code/ WORKDIR /code/ EXPOSE 8000 docker-compose.yml version: '3' services: db: image: postgres web: build: . command: bash -c "python src/manage.py runserver 0.0.0.0:8000" # volumes: # - .:/code ports: - "8000:8000" depends_on: - db .dockerignore # Byte-compiled / optimized / DLL files __pycache__/ **/migrations src/media src/db.sqlite3 Procfile .git Commands # build image sudo docker-compose up --build # to enter container sudo docker exec -it [container id] bash # to check ignored files inside the container … -
How to implement Trello-like kanban board using socket or push notifications
I am trying to implement a Trello-like board page that updates any changes to cards and lists on a board real-time (ex-card order, list order, newly added cards or deleted cards, etc) using Django Rest Framework. I was initially thinking of using Django channels and WebSocket to receive any change from frontend and return JSON containing updated information that other subscribers in the group should know. But I am now wondering if there is a way to implement this feature without using socket: For example, using Django signals to detect changes and sending some sort of notification to the frontend to reload certain sections of the page (after which the users will see the updated changes). Can this be made possible? I guess it does not have to be Django signals -- any recommendation of useful libraries or features will be appreciated, as well as any advice on approaching this task. Thank you! -
how to apply my custom content in template django-allauth
I use common template both for login purposes and other "guest visit" tasks. I dont need to special separate template for login form. But i need to apply huge content. Is it possible to apply my own content to render my own template by allauth view - accounts/login for example or i should apply another library? if i use advice: from allauth.account.views import SignupView, LoginView class MySignupView(SignupView): template_name = 'my_signup.html' class MyLoginView(LoginView): template_name = 'my_login.html' i have error, because my 'my_login.html' includes many variables for rendering and i can`t apply my content - i dont now, how i can do it. another advice: <div class="fieldWrapper"> {{ form.email.errors }} <label for="{{ form.email.id_for_label }}">Your email address:</label> {{ form.email }} </div> <div class="fieldWrapper"> {{ form.username.errors }} <label for="{{ form.username.id_for_label }}">Your Username:</label> {{ form.username }} </div> <div class="fieldWrapper"> {{ form.password1.errors }} <label for="{{ form.password1.id_for_label }}">Password:</label> {{ form.password1 }} </div> <div class="fieldWrapper"> {{ form.password2.errors }} <label for="{{ form.password2.id_for_label }}">Password(again):</label> {{ form.password2 }} </div> is to use form fields in my custom template and render it by myself def guestVisit(request): return render( request, "index.html.j2", { 'LoginForm': LoginForm(), 'GuestMesForm': GuestMesClearForm, 'user': request.user, 'loginEnb': request.META['REMOTE_ADDR'] in AVALABALE_IP } ) is a good idea, but if i have error … -
Issues with select drop down filtering django
i have issues getting the output of my experience_level and country select fields despite my best efforts,please kindly help,below are snippets of my code for better understanding //a choice.py file to store all my selections salary_choices = { '100000': '$100,000', '200000': '$200,000', '300000': '$300,000', '400000': '$400,000', '500000': '$500,000', '600000': '$600,000', '700000': '$700,000', '800000': '$800,000', '900000': '$900,000', '1000000': '$1M+', } Country_choices = { 'US': 'United States', 'AF': 'Afghanistan', 'AL': 'Albania', 'DZ': 'Algeria', 'AS': 'American Samoa', 'AD': 'Andorra', 'AO': 'Angola', 'AI': 'Anguilla', 'AQ': 'Antarctica', 'AG': 'Antigua And Barbuda', 'AR': 'Argentina', 'AM': 'Armenia', 'AW': 'Aruba', 'AU': 'Australia', 'AT': 'Austria', 'AZ': 'Azerbaijan', 'BS': 'Bahamas', 'BH': 'Bahrain', 'BD': 'Bangladesh', 'BB': 'Barbados', 'BY': 'Belarus', 'BE': 'Belgium', 'BZ': 'Belize', 'BJ': 'Benin', 'BM': 'Bermuda', 'BT': 'Bhutan', 'BO': 'Bolivia', 'BA': 'Bosnia And Herzegowina', 'BW': 'Botswana', 'BV': 'Bouvet Island', 'BR': 'Brazil', 'BN': 'Brunei Darussalam', 'BG': 'Bulgaria', 'BF': 'Burkina Faso', 'BI': 'Burundi', 'KH': 'Cambodia', 'CM': 'Cameroon', 'CA': 'Canada', 'CV': 'Cape Verde', 'KY': 'Cayman Islands', 'CF': 'Central African Rep', 'TD': 'Chad', 'CL': 'Chile', 'CN': 'China', 'CX': 'Christmas Island', 'CC': 'Cocos Islands', 'CO': 'Colombia', 'KM': 'Comoros', 'CG': 'Congo', 'CK': 'Cook Islands', 'CR': 'Costa Rica', 'CI': 'Cote D`ivoire', 'HR': 'Croatia', 'CU': 'Cuba', 'CY': 'Cyprus', 'CZ': 'Czech Republic', 'DK': 'Denmark', 'DJ': 'Djibouti', 'DM': 'Dominica', 'DO': … -
TypeError at /edit : edit() missing 1 required positional argument: 'entry'
I am very new at Django and I am working on a web app project. this particular page is supposed to edit an entry and save the entry. but I keep getting the missing 1 required argument Views.py # editPage forms class editform(forms.Form): content = forms.CharField(widget=forms.Textarea(), label='') def edit(request, entry): if request.method == 'GET': page = util.get_entry(entry) return render(request,"encyclopedia/edit.html",{ "form":SearchEntry(), "edit":editform(initial={'content': page}), "entry":entry }) #If this is a POST request else: form = editform(request.POST) if form.is_valid(): content = form.cleaned_data["content"] util.save_entry(entry,content) page = util.get_entry(entry) page = mark.convert(page) return render(request,"encyclopedia/entry.html",{ "form":SearchEntry(), "page":page, "entry": title }) urls.py from django.urls import path from . import views urlpatterns = [ path("", views.index, name="index"), path("wiki/<str:entry>", views.entry, name="entry"), path("search", views.search, name="search"), path("newEntry", views.newEntry, name="newEntry"), path("edit", views.edit, name="edit"), edit HTML {% extends "encyclopedia/layout.html" %} {% block title %} Edit {{name}} {% endblock %} {% block body %} <h1>{{title}}</h1> <form action= "{% url 'edit' %}" method="POST"> {% csrf_token %} {{ edit }} <br> <input class="save btn btn-info" type="submit" value="save"/> </form> <p> Click the "save" button to save your entry to the encyclopedia.</p> <br> <a href = "{% url 'index' %}"> Return Home</a> {% endblock %} entry HTML {% extends "encyclopedia/layout.html" %} {% block title %} Encyclopedia {% endblock %} … -
find out why my web server becomes unavailable
I have a python web server (django) It talks to other services such as elasticsearch I notice when elasticsearch goes down, the web server soon (after a few minutes) stops responding to client requests. I use https://github.com/elastic/elasticsearch-py and it implements timeout and don't think it's blocking. My hunch is that requests piles up during the timeout period and server becomes unavailable but it's a just guess. What's the reason for the server not being able to handle requests in such a scenario and how do I fix it? I have nginx - uwsgi - django on unix (amazon ecs) setup if that makes difference