Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django CKEditor different toolbar settings for django admin
Is there any way to set the different CKEditor toolbar settings for the Django Admin Panel with django-ckeditor. My toolbar settings in settings.py looks as below 'toolbar_Custom': [ ['Format', 'Bold', 'Italic', 'Link', 'NumberedList', 'BulletedList', 'Table', 'HorizontalRule', 'Image', 'Youtube', 'Smiley', 'Undo', 'Redo', 'Preview', 'Source'], ], I want to set just ['Format', 'Bold', 'Italic', 'Link', 'Undo', 'Redo'] for non-admin pages. -
Transferring multiple values from template to views - Django
I am working on a simple game where the user can select many numbers in the template and then I would like to pass them on to the views. My template looks like this: <div class="col-lg-2"> <div class="card text-center bg-gradient-primary border-0 hover-shadow-lg hover-translate-y-n3 mb-4 ml-lg-0"> <div class="card-body"> <div class="d-inline-flex align-items-start"> <div class="pl-0"> <span class="d-block h2 text-white mr-2 mb-1"><b>1</b></span> </div> </div> </div> </div> </div> <div class="col-lg-2"> <div class="card text-center bg-gradient-primary border-0 hover-shadow-lg hover-translate-y-n3 mb-4 ml-lg-0"> <div class="card-body"> <div class="d-inline-flex align-items-start"> <div class="pl-0"> <span class="d-block h2 text-white mr-2 mb-1"><b>2</b></span> </div> </div> </div> </div> </div> Now the user selects the field 9, 13, 16, 19, 22. I would like to pass all the values at once after click button "Choices number". Without refreshing the page (until the button is clicked). How can I do this? I was thinking about using a hidden field <input type="hidden" name="number1" value="1"> but it would refresh every time my template. One option would be to pass the value using method get, setting something like that for each card element href=?button_number_1=1 and then, get them in the view using request.GET['button_number_1']. And avter this save all using method post. But maybe there is another way to do it? Any help … -
How to fix "origin 'null' has been blocked by CORS policy" when authenticating Angular/Django with external SSO service?
My application has a Django backend and Angular frontend. If the user tries to access the backend directly, it authenticates correctly. However, when a user goes to the Angular frontend I get the following error: redirected from [site] from origin 'null' has been blocked by CORS policy The basic flow in this case is Angular will authenticate with a Django api. If the user is not logged into Django, they will be redirected to an external SSO api, authenticated, and redirected back. From what I've read, the reason the origin is 'null' is due to this redirect. That being said, I am not sure on how to implement this authentication process without doing the redirects. Is there a way around this issue? -
Math Operations on DateField Django
When someone makes an entry, the date and time will be recorded as expected. What I'm curious about is how to do math operations on that date. Like I want to show the date of when the object was created, and also the date 2 weeks in the future. models.py from django.db import models class Checkout(models.Model): member_id = models.IntegerField(null = True) title = models.CharField(max_length = 1000) date_checkout = models.DateField(auto_now = True) # expected_return = date_checkout * 2 I thought I had stumbled across a useful resource online that mentioned something about this but I can't find it anymore. If you could just point me to some resources online that would be awesome. -
Django formtools, how to set wizard_view cookie expiration date?
I am using django formtools to split a long form. I want users to have the possibility to continue filling the forms after they logout/login to the site and after closing/opening their browser. However, the cookie set by formtools has an expiration date value of Session. Therefore, if the user closes the browser the cookie is deleted and the user must start filling the form from the beginning. Is there any way to set the cookie wizard_submissions_wizard_view in the picture below to let say the 2019-01-01? -
Django REST Framework tutorial sends Page Not Found on part 1
I'm new to Django and API developing, so I started following Django REST Framework tutorial, and I have an error in the first part of it. When I go to "127.0.0.1:2000/" on my browser, the Api Root page appears (I hosted it on port 2000), so it seems to be working, but when I try to go to "127.0.0.1:2000/snippets/", I get a Page Not Found error. I imagine this is a very simple thing I'm just overlooking, but I'm kind of stuck right now, and would appreciate the help. Should my "tutorial/urls.py" include the snippets in any way? I followed the tutorial from the beginning, and re-viewed it, so I don't think so, but its a hypothesis. -
Django Rest Framework - Can't avoid null fields being serialized in response
I have this class: class PropertySerializer(serializers.ModelSerializer) class Meta: model = Properties fields = ( 'key', 'value' ) I'm serializing a ManyToManyField field in a model leading to Properties. It has only one record. This is what I'm getting (which is correct): properties": [ { "key": "test_property", "value": null, } ] This is accurate, but I'd like to filter out all null value fields. So far everything I tried failed. Still getting the null value serialized out. I tried: setting blank=False on the value field in the Properties Model. adding value = serializers.CharField(allow_null=False) to PropertySerializer adding extra_kwargs = {'text': {'allow_null': False}} to PropertySerializer What am I doing wrong? Is there a working elegant way other than manually iterating the serializer.data and removing all null values myself? -
Session key changing after login
I am trying to save data of anonymous user if in future the user decides to become a authenticated user but it seems when I am trying to get data of anonymous user using session key after login, the key changes. I want to use the same key after login as well hoe can i do that? Any help will be greatly appreciated, Thank You. Below is the views.py of the code where I am trying to retrieve data. -
Using mod rewrite to preserve // in a parameter inside a url
I am passing a parameter in a URL and sometimes it has a // inside of the parameter that I need to keep but my apache/mod_wsgi config replaces it with a single / . This is a problem since I am performing queries using the parameter and they will come up as they do not exist. I tried writing some rules into my views to handle this but it doesn't work well with the classes that I am using. Can someone help me with some mod_rewrite statements to handle this? A couple examples of the urls are: http://98.8.61.133:8080/viewLit/OGYX/106462//ZYO/ http://98.8.61.133:8080/viewLit/OGYX/106462//ZYO/edit http://98.8.61.133:8080/viewLit/WS/KJUS/260849/ / WXN / http://98.8.61.133:8080/viewLit/01/KG--/069265/ /SED/ http://98.8.61.133:8080/viewLit/49/KFGS/273672//MS/ The /edit needs to be preserved as well because this is what directs the url to another view. I did write some rules in python that look like this that worked on functions but not classes: ruleList=["/SB", "/ZYO", "/ZYO /", "/MS", "/CLVI", "ELG"] for rule in ruleList: if(len(re.findall(rule + "$", circuitid))>0): circuitid=re.sub(rule+"$","/"+rule, circuitid) record = Circuitinfotable.objects.get(circuitid=circuitid) I need to handle this before it gets passed back to my python classes and thought that mod_rewrite might be the right way? I am new to apache but I started to try it and I am lost: … -
html after {% block content %} and {% endblock content %} is showing before the content in Django?
I have a base and child templates. In my base html file i have this: <html> <head> <title>{% block title %}{% endblock %}</title> </head> <body> <ul id="barra"> <li>Inicio</li> <li>Enlace1</li> <li>Enlace2</li> <li>Enlace3</li> <li>Enlace4</li> <li>Ayuda</li> </ul> {% block content %} {% endblock %} </br> <a>asdasdasdasdasdasd</a> </body> </html> but when i see the web in a browser, the "asdasdasdasdasdasd" is shown below ul and over {% block content}. See image Does anyone knows the origin of this behavior, i think its a really simple structure and i cant get why its failing. Thank you very much! -
500 error: null value in column "timeline_id" violates not-null constraint
I'm currently a student and am trying to create a full stack web application with python/django and React. While building my back-end I have run into a problem where, when posting an object containing an association, the association's id is lost between the response payload and the database. I know that the state is updating as it should and that other objects that don't use associations on the back-end can be created without a problem. I assume my mistake has to be somewhere in the models or serializers that I made, but so far I haven't found it. 500 error message: Integrity error at "api/v1/event" null value in column "timeline_id" violates not-null constraint DETAIL: failing row contains (index_id, junk_data, junk_data, 1, null) my models: from django.db import models class Timeline(models.Model): name = models.CharField(max_length=50, default='n/a') def __str__(self): return self.name class Event(models.Model): name = models.CharField(max_length=25, default='n/a') description = models.CharField(max_length=150, default='n/a') coordinate = models.IntegerField(default=0) timeline = models.ForeignKey(Timeline, on_delete=models.CASCADE, related_name="events") def __str__(self): return self.name class Note(models.Model): article = models.TextField(default='n/a') event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name='notes') # event = models.ManyToManyField(Event) def __str__(self): return self.article my views: from rest_framework import viewsets from .serializers import TimelineSerializer, EventSerializer, NoteSerializer from .models import Timeline, Event, Note class TimelineView(viewsets.ModelViewSet): queryset = … -
Is it possible to Sum time (02:41:54) in Django?
I am getting time base 24 hrs from data base. (example: 02:25:41) I want to Sum all of them and I was wondering if that is possible. I mean just Suming 02:25:41 + 01:05:01 = 03:30:42, for example I was thinking in converting time into seconds then Sum the Integers and then convert them again into HHMMSS. That is what I was doing until now, just suming the seconds and then convert them into HHMMSS but that was because I was getting seconds from data base here things have changed since I am not getting seconds but Time. this is what I´ve been doing until now query_t = jssDatejj.objects.values('direction') \ .filter(date__range=(start, end)).order_by('direction').annotate( serv= Sum('serv20'), servicioR= Sum('serv10'), servicioA= Sum('serv11'), pavgmt= Sum('prom20'), pavgst= Sum('prom10'), sClient= Sum('clients'), sDeriv= Sum('deriv'), sAten= Sum('aten'), service= Round(Cast(Sum('serv20'), FloatField())/Cast(Sum('serv10'), FloatField()))*100, tme= Sum('promedio_avgmt') / Sum('serv10'), tmo= Sum('promedio_avgst') / Sum('serv11'), totalTmp = Sum('deriv') + Sum('aten') ) all those values are send to html where I use them and convert them into HHMMSS through javascrit to be printed in a Datatable. so I need to add 2 more values but are sent in time (02:04:52) and I can´t Sum them just the way I have been doing it -
why is dj-database-url throwing me an error of : a bytes-like object is required, not 'str'
so i am a student attempting to create a django based app...my app is finished and im wanting to launch it on heroku. The error message comes when i run: python3 manage.py makemigrations I am using dj-database-url for the db url and have the env stored as : DATABASES = {'default': dj_database_url.parse(os.environ.get('DATABASE_URL'))} The versions of everything I am using are: chardet==3.0.4 dj-database-url==0.5.0 Django==2.2.7 heroku==0.1.4 idna==2.8 psycopg2==2.8.4 python-dateutil==1.5 pytz==2019.3 requests==2.22.0 sqlparse==0.3.0 stripe==2.40.0 urllib3==1.25.7 and the traceback error message I am receiving is : File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\Jakey Poo\PycharmProjects\artwork\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line utility.execute() File "C:\Users\Jakey Poo\PycharmProjects\artwork\venv\lib\site-packages\django\core\management\__init__.py", line 325, in execute settings.INSTALLED_APPS File "C:\Users\Jakey Poo\PycharmProjects\artwork\venv\lib\site-packages\django\conf\__init__.py", line 79, in __getattr__ self._setup(name) File "C:\Users\Jakey Poo\PycharmProjects\artwork\venv\lib\site-packages\django\conf\__init__.py", line 66, in _setup self._wrapped = Settings(settings_module) File "C:\Users\Jakey Poo\PycharmProjects\artwork\venv\lib\site-packages\django\conf\__init__.py", line 157, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "C:\Users\Jakey Poo\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "C:\Users\Jakey Poo\PycharmProjects\artwork\artwork\settings.py", line 89, in <module> … -
try to read csv using python to pythonanywhere host
We try to read csv file using view.py in pythonanywhere.com host. We try to get three cells (id, statement, and paragraph) from each row in the 1.csv file until last one. The code is: def home(request): Stats = Statments.objects.all() __file__ = '1.csv' module_dir = os.path.dirname(__file__) # get current directory file_name = os.path.join(module_dir, 'Politi_Stat/1.csv') #Load statments to database from CSV with open(file_name,"r", encoding = 'utf-8') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') for row in csv_reader: book = Statments(id = row[0] ,statment=row[1], Paragraph=row[2]) book.save() d = deque(posts) d.extendleft(reversed(Stats)) We import the csv and os. It seems an encoding problem of the unicode UTF-8 of csv. The output of the site is: Server 500 The output from the log file is: Traceback (most recent call last): File "/home/fattoh/.virtualenvs/django2/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/home/fattoh/.virtualenvs/django2/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/fattoh/.virtualenvs/django2/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/fattoh/Politi_Stat/app/views.py", line 46, in home for row in csv_reader: File "/home/fattoh/.virtualenvs/django2/lib/python3.7/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 82: invalid start byte 2019-11-27 19:20:54,714: Internal Server Error: / Traceback (most recent call last): File … -
Error 500 when Debug off on both local and Heroku with Whitenoise
I'm having alot of trouble either understanding how to properly host my static files on both local and heroku. Currently when Debug is turned off, I get an error 500- otherwise it works fine. I've read quite a few SO posts but so far, no solution has helped. Below is my code: settings.py INSTALLED_APPS = [ 'widget_tweaks', 'django_select2', 'masterform', 'tempus_dominus', 'team', 'sms', 'opportunities', "rest_framework", 'import_export', 'whitenoise.runserver_nostatic', 'django.contrib.staticfiles', ] STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), ) STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' STATIC_ROOT = os.path.join(BASE_DIR, "live-static", "static-root") urls.py from django.views.static import serve from bdsurveyapp import settings urlpatterns = [ url('', include('opportunities.urls')), url(r'^sms/', include('sms.urls')), url(r'^admin/', admin.site.urls), path('accounts/', include('django.contrib.auth.urls')), url(r'^dashboard/', include('dashboard.urls')), path('login/', auth_views.LoginView.as_view(template_name='pages/login.html'), name="login"), path('logout/', auth_views.LogoutView.as_view(template_name='pages/logout.html'), name="logout"), url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}), ] partial base.html <!DOCTYPE html> <html lang="en"> {% load static %} <head> {{ form.media.css }} <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content=""> <meta name="author" content=""> <link rel="apple-touch-icon" sizes="180x180" href="{% static 'img/apple-touch-icon.png' %}"> <link rel="icon" type="image/png" sizes="32x32" href="{% static 'img/favicon-32x32.png' %}"> <link rel="icon" type="image/png" sizes="16x16" href="{% static 'img/favicon-16x16.png' %}"> <link rel="manifest" href="{% static 'img/site.webmanifest' %}"> <link rel="mask-icon" href="{% static 'img/safari-pinned-tab.svg' %}" color="#5bbad5"> <meta name="msapplication-TileColor" content="#da532c"> -
Filter using Q in Django , when multiple inputs can be null
I have a model product_details, with the following fields brand_name,model_name, bodystyle, transmission, and min_price, max_price Example of budget values in the dropdown is 1 - 5 5 - 10 10 - 15 I have 5 select dropdown fields on the basis of which I want to filter my results. I am using the method below to filter based on first three fields def select(request): q1 = request.GET.get('brand') q2 = request.GET.get('model') q3 = request.GET.get('bodyStyle') #q4 = request.GET.get('budget') cars = product_details.objects.filter(Q(bodystyle__icontains=q3)|Q(brand_name__icontains=q1)|Q(model_name__icontains=q2)) #cars = product_details.objects.filter(bodystyle=q3) return render(request, 'search/search_results.html', {'cars': cars}) I have two questions 1: How do I filter if only 1 or 2 values are selected from dropdowns. What should be my if condition? 2. How do I filter on the basis of range for budget fields? Since the budget needs to be compared with min_price and max_price. Any help or guidance would be appreciated. -
How could I remove the "import error" I am receiving on Django
I am watching this video to learn more about Django https://www.youtube.com/watch?v=v7xjdXWZafY my code is exactly like his however I am getting an import error. It says "no modules named urls" This is my code: from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('', include('weather.urls')), ] -
Why is Django not adding an entry to my Model table?
I am using an HTML page in Django's Views as well as other helper functions in Views to take data from form fields in the HTML page and send them to one of the Models databases through Django. This is all done off of my local host. I'm basing what I'm doing off of this solution. When I hard code an entry and send it from views to models, there isn't an issue. When I try to take data from the HTML field and then send it, I get a code 200, but logging into the admin panel and trying to access the database causes the local host server to crash, and the data is not entered into the table. Below is my code: Views Functions for getting and sending table entry to Models def addCharacter(sUserID, sPlayerName, sRace, sPlayerClass, sStr, sCon, sDex, sInt, sWis, sCha): from pathfinder.models import characterTable c = characterTable(userID = sUserID, playerName = sPlayerName, race = sRace, playerClass = sPlayerClass, strength = sStr, constitution = sCon, dexterity = sDex, intelligence = sInt, wisdom = sWis, charisma = sCha) c.save() #this function courtesy of Mahshid Zeinaly on stackoverflow https://stackoverflow.com/a/19761466/12352379 def request_page(request): if(request.GET.get('mybtn')): userID = 'testUser' addCharacter(userID, string(request.GET.get('characterName')), string(request.GET.get('race')), … -
Django fixture for a model with no fields?
If I have a Django model, with some field(s) defined: # model.py from django.db import models class Model(models.Model): text = models.CharField(max_length=10) I can initialize it by using a fixture: # sample.yaml - model: app.Model pk: 1 fields: text: "some text" with the command: manage.py loaddata sample.yaml and everything works fine. My problem is that I cannot do the same for a model with no fields: # model.py from django.db import models class Model(models.Model): pass # sample.yaml - model: app.Model pk: 1 fields: Then the same manage.py loaddata sample.yaml command gives an error: Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/django/core/serializers/pyyaml.py", line 73, in Deserializer yield from PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options) File "/usr/local/lib/python3.8/site-packages/django/core/serializers/python.py", line 112, in Deserializer for (field_name, field_value) in d["fields"].items(): AttributeError: 'NoneType' object has no attribute 'items' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 23, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 72, in handle self.loaddata(fixture_labels) File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 114, in loaddata self.load_label(fixture_label) File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 172, in … -
trouble install mysqlclient on ubuntu18.04
I am trying to install mysqlclient on ubuntu 18.04 for a Django project but having problem installing mysql. Here is the information from terminal: MySQLdb/_mysql.c:29:10: fatal error: mysql.h: No such file or directory #include "mysql.h" ^~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 -
Django - when user clicks button, get text in separate div tag, send it to the views.py and update the value for that user in the model
I am new to Django and the Front-end. The project I am working on is an E-Learning site where a user can go on a page (I call it a slide page) that has a text editor in it, and has to solve problems and does so via the text editor. When the user first visits a slide page that they have not been on before, a new record in the Slides model is added, and the value for the 'code' column (which is the text that is in the text editor) is automatically set to what is in that column for the admin (pre-defined text such as variables and comments). Then when the user updates the text in the text editor with their answer to the coding problem on the page and clicks any of the buttons on the page, I want to check this updated text with what is already in the 'code' column in the Slides model for that user (1 row per user for each slide), and if there is a difference, update the value of the 'code' column for that user in the Slides model. I tried playing around with some jQuery in the boolean.HTML … -
HTML Button Not Taking Up Full Width of Parent Div
I have an area on my website where events are listed. I have a parent div for the container and a div for each event section. When the user hovers over the section, an edit and delete button pops up on the left: The problem is the button isn't taking up the full width of the div, but only is as long as the text is. I know other questions have been asked, but none of the answers, such as adding box-sizing: border-box, work for me. HTML code: <div class="col-md-6 inline mb-4"> <h3 class="ml-2">Reminders:</h3> <div class="events-content-section ml-2"> {% for reminder in reminders %} <div class="mb-2" style="display: flex; align-items: center;"> <ul class="reminderUl"> <li> <span class="reminderSpan"> <button type="button" class="update-reminder btn btn-info" data-id="{% url 'update-reminder' reminder.pk %}"> <i class="fas fa-pencil-alt"></i> </button> </span> <span class="reminderSpan"> <button type="button" class="delete-reminder btn btn-danger" data-id="{% url 'delete-reminder' reminder.pk %}"> <i class="fas fa-trash-alt"></i> </button> </span> <button class="view-reminder btn btn-light" data-id="{% url 'view-reminder' reminder.pk %}"> <h4>{{ reminder.title }}</h4> </button> </li> </ul> </div> {% endfor %} </div> </div> -
Calculate next due date based on start date frequency and current date
I apologize if this has already been asked...I saw something for excel but I'm trying to do this in python. I have the following model: Class AccountDetails(models.Model): name = models.CharField(max_length=30, null=True) due_date = models.DateField(auto_now=False, auto_now_add=False, null=True) frequency_choices = [ ('weekly', 'Weekly'), ('bi-weekly', 'Bi-Weekly'), ('twice-monthly', 'Twice Monthly'), ('monthly', 'Monthly'), ('yearly', 'Yearly') ] frequency = models.CharField( max_length=15, choices=frequency_choices, default="weekly", ) I'm creating a plotly-dash datatable using pandas and I need to create a column titled "next_due_date". I want the value to be the next due date based on a start date, the current date, and a frequency. Example: due_date: 12/22/2017 frequency: Bi-Weekly current date: 11/27/2019 next_due_date should be: 12/6/2019 I'm pretty stuck on this one. Any help would be greatly appreciated! -
The for loop inside the school_list.html is not returning the names
the school_list.html file in the project is not displaying the list of school names .it just only prints the heading . I have added the link to complete project files in the linnk.Github link for project -
How to browse a webserver running in a docker container when the container itself is running in an AWS EC2 instance?
I have a Django webserver running in a docker container. When the container is running locally, I can see the server running by using a browser to point to the localhost port mapped with the exposed port of the container. Now I have the same container running in an AWS EC2 instance. The container's exposed port has been mapped to a certain port of the AWS instance. How can I browse the running webserver from local? (I connect to the AWS EC2 using SSH)