Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
my api call doesnot work in javascript but works fine with in postman and browser
this the html file <html> <head> <title>"api call"</title> </head> <body> <div id="demo"> <script> function list() { var xhttp = new XMLHttpRequest(); xhttp.open("GET","192.168.0.101:8000/students/",true); xhttp.setRequestHeader("Content-type", "application/json"); xhttp.setRequestHeader("Authorization", "Token ad4140b1caa4f98160bdc979a71a7215ae5972fe"); xhttp.send(); var1 response = JSON.parse(xhttp.responseText); document.write(var1); } </script> <button type="button" onclick="list()">click to get the list</button> </div> </body> </html> when i run this in my browser request is not sent(i cannot see anything in my traceball in backend) the url works fine if used in the browser and postman this is the postman request and response the backend is in django -
Error handling in django-registration send_activation_email()
I have what seems like what may be common problem, but I'm having trouble finding a detailed answer. Short version: I am having trouble handling exceptions in send_activation_email of the django-registration backend due to 400 API errors. This causes the registration process to fail without an effective way to handle this or let the user try a different email address. Long version: I have a Django 1.11 project using django-registration-redux to handle the registration workflow with a custom form class. Everything seems to work well. Recently, I switched to using Sparkpost as my email backend. Due to stricter sending guidelines, occasionally a registration email is rejected due to System policy (400 error). That's understandable, but I can't find a reasonable way to handle these errors as all of the registration work is done in the background. Here is the big, ugly traceback: File "/Users/rob/src/dm_env/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner response = get_response(request) File "/Users/rob/src/dm_env/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response response = self._get_response(request) File "/Users/rob/src/dm_env/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/rob/src/dm_env/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/rob/src/dm_env/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view return self.dispatch(request, *args, **kwargs) File "/Users/rob/src/dm_env/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper return bound_func(*args, **kwargs) β¦ -
How should I model a schema in which models can be related to entities of different types in Django
Schema Option 1: https://gist.github.com/guyjacks/6ec4c1b0fa41b3f666f5c6adf2dfaf89 Schema Option 2: https://gist.github.com/guyjacks/4838cd76b2f924629d2a3f2ba316a504 I guess this is really two questions: Which schema is recommended from a relational db perspective? Is there an idiomatic way to model either schema in Django? Cheers! -
displaying modal in django table
Okay so I have a dynamically constructed Django table that takes a ordered dict passed to it from the context. What I want to do is truncate the data in each field and provide a modal to display the remainder of the information in a modal table. The issue I'm running into is that the same data is being displayed in each modal and I am not sure why. Below is my template and javascript code as well as the structure of the data I am working with. Any help is appreciated. Thanks. {% if data %} <section class="results-section"> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <div id='loader' class="center-block"> <p>Searching<img src='{% static "img/ellipsis.svg" %}'></p> <img class="center-block" src='{% static "img/gears.svg" %}'> </div> <table class="table table-bordered table-striped table-hover table-responsive" id="results-table" > <thead> <tr> <th style="width: 4%">#</th> <th>Study Reference</th> <th>Study Methods</th> <th>Study Data</th> <th>Study Tools</th> <tr> </thead> <tbody> {% if data %} {% for key, value in data %} <tr> <td scope="row">{{ forloop.counter }}.</td> <td> <div id="popup"> <p class="citation" data-hover="{{ value.2 }}">{{ value.1 }} <img src='{% static "img/expand-icon2.png" %}' id="expand"></p> <a class="article" target="_blank" href={{ value.3 }}>{{ value.2 }}</a> </div> </td> {% if value.4 %} <td>{{ value.4 }}<a class='test' href='#' id="trigger_{{ forloop.counter }}"><img src='{% static β¦ -
In Django, How do you write the url pattern for a json file?
My website generates json files in saves them with the user specified name: "test.json" I couldn't immediately access it,so I assumed that I would have to write a URL pattern and view to see this file. I want something akin to this : url(r'^(?P).json$',views.loadjson,name='loadjson') -
how to convert some html to pdfs then zip them using django?
I have read some posts, tried few ways to convert html into pdf and failed but then this http://ourcodeworld.com/articles/read/241/how-to-create-a-pdf-from-html-in-django helped me out. by using the pdfkit.from_string() I am able to output my string of html into a pdf file. I am now trying to bulk generate them into a pdf then put them all into a zip. Somehow I am not able to get it to work... can someone please give me a hand with what I have at the moment? # read and write string as file output = StringIO() # temp output file zip_csv_filename = 'pdfs.zip' response = HttpResponse(content_type='application/zip') response['Content-Disposition'] = 'attachment; filename=' + zip_csv_filename # open the file, writable zip = ZipFile(response, 'w') messages = Message.objects.filter() for m in messages: zip.write('100545.pdf', pdfkit.from_string(m.html, output)) zip.close() return response Thanks in advance. -
Django: Fastest way to random query one record using filter
What is the fastest way to query one record from database that is satisfy my filter query. mydb.objects.filter(start__gte='2017-1-1', status='yes').order_by('?')[:1] This statement will first query thousands of records and then select one, and it is very slow, but I only need one, a random one. what is the fastest one to get? -
Django - static files not found both locally and on Heroku
I have a problem with static files using Django with Docker on Heroku. When I open app I get errors like this on Heroku: 2017-07-13T13:37:43.271635+00:00 heroku[router]: at=info method=GET path="/static/rest_framework/js/default.js" host=myapp.herokuapp.com request_id=3bfd8d31-193e-48e8-bb6e-aee9f353ffee fwd="109.173.154.199" dyno=web.1 connect=1ms service=15ms status=404 bytes=291 protocol=https and like this locally: django_1 | [13/Jul/2017 13:35:01] "GET /static/rest_framework/js/default.js HTTP/1.1" 404 109 I tried to do it on the basis of many answers, for instance this topic, unfortunately nothing works. Any suggestions? My settings.py based on Heroku documentation: PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(PROJECT_ROOT, 'static'), ) Project tree: DockerProject βββ Dockerfile βββ Procfile βββ init.sql βββ requirements.txt βββ docker-compose.yml βββ PROJECT βββ frontend βββ all files βββ backend βββ project βββ prices βββ manage.py βββ project βββ all backend files -
DRF How to use a Token to prove authentication
I am using Django Rest Framework to build an API. I am using Token Authentication. I get a valid token when requested. Then I call another API point to request data and send my Token. I do not appear to be authenticating. When I debug print to the server my user is Annonymous and my request.auth is None. I am using Javascript in VueJS to make the call: fetchHabits: function() { console.log('Token '+this.authToken.token); fetch('http://127.0.0.1:8000/api/habit/?format=json',{ method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Token '+this.authToken.token }, }) .then(response => response.json()) .then(json => this.habits = json) } Can anyone please tell me how I pass a valid token to DRF so that it is recognized. If I have to code it within a class, where is the valid token stored? Thank you -
Django forms Input type text keeps returning value "on" clicking on the submit button.
I'm using Django forms for a registration with a checkbox at the end, but whenever I click on the submit button the value of the first input type gets changed to "on" . Note that the submit button is enabled only after the checkbox is checked . I have used jQuery to try to output the value of that specific field and indeed it does not return the value I typed but only returns "on" . I Spent hours and hours on debugging but still can't find a way out . form.html <form method="post"> {% csrf_token %} {% for field in form1 %} {{ field|as_crispy_field }} <span>{{ field.help_text|safe }}</span> {% endfor %} <div class="terms-con"> <ul> <li><input type="checkbox" id="terms" name="name"></li> <li><a href="{%url 'main:terms_conditions'%}">I agree with the terms and conditions of the site</a></li> </ul> </div> <button type="submit" id="registerBtn" name="button" disabled="disabled">Register</button> </form> forms.py class AssociationForm(forms.ModelForm): class Meta: model = Association fields = ( 'name', ) labels = { 'name': _("Association name") } widgets = { # 'name': forms.TextInput(attrs={'value': ''}), # 'year_of_creation': forms.TextInput(attrs={'placeholder': "Format: 'year-month-day'"}) } def __init__(self, *args, **kwargs): super(AssociationForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) index.js $(document).ready(function(){ console.log($('input#id_name').val()); $('#terms').click(function(){ // check if the checkbox is checked if($(this).is(':checked')){ $('#registerBtn').removeAttr('disabled'); $('#registerBtn').attr('value', true); }else{ $('#registerBtn').attr('disabled', true); β¦ -
how to stop default migration of auth.permission and contentypes while writing unit test cases in django
I am writing the test cases for views. I create some roles and mapped the users with this roles, I set permissions according to the role not by user as django provide user permission mapping table. I load initial data to the role permission table in a json file. By default django migrate auth.permission, contenttypes. And hence when I change the database it changes permissions too. It reflects to role permissions too, as each time it changes the permission for each role. How do I stop default migration of auth.permission? -
Sending Multiple Dictionaries over to a template in django
So im a little new to django and templating an I'm not sure how to go about doing this. I have a file called services.py in my project structure where i have several functions that do authentication, make a call to an api, return the data, parse it, and enter it into several dictionaries. The api loooks like this : { CheckName: "AppPools", Description: "DefaultAppPool", GroupName: "Server1", Links: [ { description: "Recycles the DefaultAppPool app pool.", link: "Recyle/Server1/DefaultAppPool", title: "Recycle" }, { description: "Stops the DefaultAppPool app pool.", link: "Stop/Server1/DefaultAppPool", title: "Stop" }, { description: "Starts the DefaultAppPool app pool.", link: "Start/Server1/DefaultAppPool", title: "Start" } ] }, { CheckName: "AppPools", Description: "FinancialServices", GroupName: "ST0PWEB12", Links: [ { description: "Recycles the FinancialServices app pool.", link: "Recyle/Server2/FinancialServices", title: "Recycle" }, { description: "Stops the FinancialServices app pool.", link: "Stop/Server2/FinancialServices", title: "Stop" }, { description: "Starts the FinancialServices app pool.", link: "Start/Server2/FinancialServices", title: "Start" } ] }, There is a hierarchy here CheckName1 GroupName1 Description1 Description2 GroupName2 Description3 Description4 CheckName2 GroupName1 Description1 Description2 GroupName2 Description3 Description4 IVe stored the data in dictionaries with the following format function called groupsInChecks creates a dict with the following format: {CheckName1:(GroupName1,GroupName2, GroupName3), CheckName2:(GroupName4,Grouonam5, GroupName6)} function called serviesInGroups β¦ -
Mocking a field in request
There are 2 frameworks - Django and Flask. Django runs the project with REST, while Flask runs an Orchestration Layer. Now there is a test, which supposed to check one of CRUD methods: @mock.patch('requests.post') def test_create(self, request_mock,): request_mock.return_value = self.response_generator.create() response = self.client.post(url_for('foo.list', account='bar'), content_type='application/json', data=json.dumps({ "name": "Foo", "type": "baz" })) self.assertEqual(response.status_code, 201) name and type are mandatory fields. name is just a string. But type is a url to the type (in the REST), so when baz is passed it uses magic to connect to the REST and retrieve data. The problem is that when running the test Django with the REST is offline, while the test still tries to connect to it resulting in timeout error. with ConnectionError: HTTPConnectionPool(host='10.10.10.10', port=8000): Max retries exceeded with url: /rest/accounts/bar/baz/ (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',)) Question: now how does one mock just that type field, so it doesn't call offline server? -
Is it safe, practical and scalable to store and execute js and html which is stored in the database as a string? (Django)
I love gulp, but it's not easy to push your gulp front-end project to production. Django especially, takes a while to push new html or js code to production. Usually you're required to Upload new html and js files execute manage.py collectstatic clear your browser cache reload the page and finally, after these four steps you can test and see if your changes to AngularJS code work. On many occasions, bugs pop up due to browser cache not being cleared, this makes Ajax testing a nightmare sometimes. So, I've come up with an alternative solution. Why not load all js css and html static files from the database instead? Django has a ton of security features and a powerful admin panel right out of the box, so why not turn Django Admin into a front-end IDE? I've come up with this so far: https://vimeo.com/225429455 Does anyone see any issues with developing front-end html apps this way? Could this be used in a production environment? -
Uncaught SyntaxError: Unexpected token & : jquery django context dict error
I am trying to assign a context dict to a jQuery variable in my django html template and I am getting the following error message in my browser's console: Uncaught SyntaxError: Unexpected token & This is how I've assigned the context value (dict) to the javascript variable: var foo = {{ bar }}; Where bar is the context variable passed from the view The context is not taken as a javascript object. Any help is much appreciated. -
Can't connect to local MySQL server through socket on Remote
I am using remote Mysql database with Django. While inserting to db with django ORM , I am getting error like Error: OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") While searching for this error I found a solution is to ensure whether DB is working or not. But in my case its remote mysql database. Settings from mongodb: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': MYSQL_DB, 'USER': MYSQL_USER, 'PASSWORD': MYSQL_PASSWORD, 'HOST': MYSQL_HOST, # Or an IP Address that your DB is hosted on 'PORT': MYSQL_PORT } } More details of error: return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5) File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 367, in mysql_version with self.temporary_connection() as cursor: File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__ return self.gen.next() File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 564, in temporary_connection cursor = self.cursor() File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 231, in cursor cursor = self.make_debug_cursor(self._cursor()) File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor self.ensure_connection() File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection self.connect() File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection self.connect() File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect self.connection = self.get_new_connection(conn_params) File "/usr/local/koob/fireball/env/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 263, in β¦ -
Display a two-way self-referencing relationship in django?
Model called "connector" could have 1 or more incoming and outgoing connections to other connectors. I like to display both in-coming/outgoing connection for any "connector" and display that perhaps in a filter_horizontal to show BOTH. So that for any connector, I can display - connector has "incoming" connections from these connectors(same model) and - connector has "outgoing" connections to other connectors(using the same model). Model.py class Connector(TimeStampModel): name = models.CharField(max_length=100, unique=True) connection = models.ManyToManyField('self', related_name='connectors' blank=True) class Meta: ordering = ('name',) Admin.py @admin.register(Connector) class ConnectorAdmin(admin.ModelAdmin): list_per_page = 30 verbose_name = 'Connector' list_display_links = ['name',] filter_horizontal = ('connection',) ordering = ('name',) list_display = [ 'name', ] -
Django group by month and year doesnt work
I've already read this Django: Group by date (day, month, year) and all related stuff by googling "django group by month" If I try the "cleanest" solution - using Django 1.11, I end up with this: class Request(BaseModel): date_creation = models.DateTimeField(default=None, blank=True, null=True) print([v for v in Request.objects.annotate(month=ExtractMonth('date_creation'), year=ExtractYear('date_creation'),) .values('month', 'year') .annotate(total=Count('month')) .values('month', 'year', 'total') ]) And the result doesn't do a group by! I get this: [{'month': 6, 'year': 2017, 'total': 1}, {'month': 7, 'year': 2017, 'total': 1}, {'month': 7, 'year': 2017, 'total': 1}] So what is the solution? This drives me nuts. -
missing 1 required positional argument: 'get_response'
So I am using Django 1.11. I used to use Django 1.9 and I remembered writing this piece of login middleware. import re from django.conf import settings from django.shortcuts import redirect EXEMPT_URLS = [re.compile(settings.LOGIN_URL.lstrip('/'))] if hasattr(settings, 'LOGIN_EXEMPT_URLS'): EXEMPT_URLS += [re.compile(url) for url in settings.LOGIN_EXEMPT_URLS] class LoginRequired: def __init__(self, get_response): self.get_response = get_response(request) def __call__(self, request): response = self.get_response(request) return response def process_view(self, request, view_func, view_args, view_kwargs): assert hasattr(request, 'user') path = request.path_info.lstrip('/') if not request.user.is_authenticated(): if not any(url.match(path) for url in EXEMPT_URLS): return redirect(settings.LOGIN_URL) However, I think something changed but I'm not sure what. I get the error:__init__() missing 1 required positional argument: 'get_response' Any ideas? -
Can I run Django channels together with normal Django
I have a Django app running on Heroku. I've been reading up on Django Channels and it looks quite interesting. Can I run Django channels together with my normal/traditional Django app? Or do I have to pick between the one of the two? -
Django redirects error when using Squid
I having an Internal Server Error (500) when saving a microsite in my Django website. The error trace is the following (I changed some not relevant parts): Internal Server Error: /admin/microsite/microsite/103271/event_section_admin/add/https, https://www.my.com/admin/microsite/microsite/103271/event_section_admin/107195/ Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/var/www/django/mywebsite/myapp/base/admin.py", line 318, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File "/usr/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/var/www/django/mywebsite/myapp/base/adminsite.py", line 73, in inner return view(request, *args, **kwargs) File "/var/www/django/mywebsite/myapp/base/admin.py", line 377, in parse_path return callback(request, *args, **kwargs) File "/var/www/django/mywebsite/myapp/base/admin.py", line 318, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File "/usr/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/var/www/django/mywebsite/myapp/base/adminsite.py", line 73, in inner return view(request, *args, **kwargs) File "/var/www/django/mywebsite/myapp/base/admin.py", line 350, in parse_path basecontent = self._get_base_content(request, object_id) File "/var/www/django/mywebsite/myapp/base/admin.py", line 468, in _get_base_content obj = model.objects.get(pk=unquote(object_id)) File "/usr/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 325, in get clone = self.filter(*args, **kwargs) File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 679, in filter return self._filter_or_exclude(False, *args, **kwargs) File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 697, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1309, in add_q clause, require_inner = self._add_q(where_part, self.used_aliases) File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1337, in _add_q allow_joins=allow_joins, split_subq=split_subq, File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1199, in build_filter β¦ -
Beautifulsoup error while deploying to heroku
i am trying to deploy my Django app to heroku. When i push heroku master it gives an error in the shell. It says push rejected because no matching distribution found for beautifulsoup4=4.0.0b3 it says could not find a version that satisfies the requirement beautifulsoup4=4.0.0b3 How can i solve this? Thank you very much. -
Running Django locally with heroku fails due to missing Procfile
I have a Django 1.11/Python 3.5 app that I built and want to run on Heroku locally. It's a simple SPA using the Heroku Django template provided on GitHub (https://github.com/heroku/heroku-django-template). I followed a Heroku tutorial (https://devcenter.heroku.com/articles/deploying-python#how-to-keep-build-artifacts-out-of-git), but I cannot seem to run the app locally using the following command: heroku local web Running this produces the following error: return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ Error: EACCES: permission denied, open '.env' at Object.fs.openSync (fs.js:584:18) at Object.fs.readFileSync (fs.js:491:33) at loadEnvsFile (/snap/heroku/414/lib/node_modules/heroku-cli/node_modules/foreman/lib/envs.js:133:15) at Array.map (native) at loadEnvs (/snap/heroku/414/lib/node_modules/heroku-cli/node_modules/foreman/lib/envs.js:148:30) at Command.<anonymous> (/snap/heroku/414/lib/node_modules/heroku-cli/node_modules/foreman/nf.js:72:16) at Command.listener (/snap/heroku/414/lib/node_modules/heroku-cli/node_modules/commander/index.js:301:8) at emitTwo (events.js:106:13) at Command.emit (events.js:194:7) at Command.parseArgs (/snap/heroku/414/lib/node_modules/heroku-cli/node_modules/commander/index.js:615:12) My .env file looks like this: WEB_CONCURRENCY=3 SECRET_APP_KEY="xxxxxxxxxxxxxxxxxxxx" I ran chmod 777 on .env but I get the same error. When I run the following command: heroku local I get the following error: [WARN] EACCES: permission denied, open 'Procfile' [FAIL] No Procfile and no package.json file found in Current Directory - See run.js --help βΈ Cannot convert undefined or null to object My Procfile looks like this: web: gunicorn personal_website.wsgi Now I cannot understand why when running "heroku local web" I get the previously mentioned error, especially after giving it the necessary permissions. Also, others have had the same error when β¦ -
Why does django-storages S3 delete the same object multiple times?
When I run python manage.py collectstatic --no-input on my production server, I get very mysterious output: $ python manage.py collectstatic --no-input Calling s3:head_object with {'Bucket': 'example-bucket', 'Key': 'static/staticfiles.json'} Starting new HTTPS connection (1): s3.amazonaws.com Starting new HTTPS connection (1): s3-eu-west-1.amazonaws.com Calling s3:get_object with {'Bucket': 'example-bucket', 'Key': 'static/staticfiles.json'} Calling paginated s3:list_objects with {'Bucket': 'example-bucket', 'Prefix': 'static'} # Weirdness starts here: Calling s3:delete_object with {'Bucket': 'example-com', 'Key': 'static/main/normalize.be7f3425b444.css'} Calling s3:delete_object with {'Bucket': 'example-com', 'Key': 'static/main/normalize.be7f3425b444.css'} Post-processed 'main/normalize.css' as 'main/normalize.be7f3425b444.css' # etc Why is the same object static/main/normalize.be7f3425b444.css being deleted twice? Furthermore, when I go to see if the file does exist in the bucket, it does! What is creating it? Why isn't there a log entry saying that the object has been created? I have object versions enabled in my S3 bucket, and here is the history of this particular object: - Jul 13, 2017 3:29:56 PM (Latest version) Standard - Jul 13, 2017 3:29:56 PM Standard - Jul 13, 2017 3:29:56 PM (Delete marker) - Jul 13, 2017 3:29:56 PM (Delete marker) - Jul 13, 2017 3:29:55 PM Standard - Jul 13, 2017 3:29:55 PM Standard - Jul 13, 2017 3:29:55 PM (Delete marker) - Jul 13, 2017 3:29:54 PM (Delete β¦ -
Writing custom Exceptions in Django
What I am trying to achieve is to make an object similar to django.http.Http404 that I will able to call it with the raise command. Use case: def some_view(request): . . .. some code .. some_function() return HttpResponse("OK") def some_function(): . . .. some code .. if all_good: return ok_object else: raise MyCustomException("Mmm.. WRONG!", status=415) What I'm trying to achieve is having this object receive some text, and a status code and make it plant this text on some template I have. I thought about writing my own object, who would just return some kind of response, but this doesn't work in use cases like above of nested usage. Also I don't want to check the returned object of some_function for its instance. This seem pretty standard thing to do, so one will be able to attach his own template and operation for exceptions within django, but I Googled this pretty hard and all I find is how to customize the template.