w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Does Django pick template changes when DEBUG=False? Yes, but HOW?
Django does not cache the loading of templates by default. Because they are not cached, they get loaded from disk every time they are rendered and that is why you'll see template changes without reloading the application. If you're interested in caching the template loading process to improve performance (it will help a lot if you are rendering a number of different templates per request), take a look at this post.

Categories : Django

Server Error (500) on Django when template debug is set to False?
Change your LOGGING settings to below code, then you should be able to get the error in the console. LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' }, 'console':{ 'level': 'DEBUG', 'class': 'logging.StreamHandler', }, }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } } remember to set DEBUG = False

Categories : Django

Django site doesn't work with DEBUG=False
This Stackoverflow question will help you: Django's SuspiciousOperation Invalid HTTP_HOST header There's a ticket opened regarding this matter: https://code.djangoproject.com/ticket/19866

Categories : Python

Django debug mode False then the page doesn't work
if it's django 1.5 it could be related to allowed host setting https://docs.djangoproject.com/en/1.5/ref/settings/#std%3asetting-ALLOWED_HOSTS

Categories : Python

What those Django documentation means by: "If DEBUG is set to False, all responses will be “Bad Request (400)”
It means that If debug is set to true you'll only see the traceback for debugging. If debug is set to false in order to render your 404 view you need to configure in yoursite.settings the ALLOWED_HOSTS setting, as they say ['localhost', '127.0.0.1'] in the case of local development. Of course in order to render a 404 you'll have to specify it in yourapp.views ...

Categories : Django

django admin django.contrib.staticfiles
The Django Book is a little out of date (although an update is in the works I believe): This book was originally published by Apress in 2009, and covered Django 1.0. Since then, it’s languished. We’re working on getting the book updated to cover Django 1.4, 1.5, and beyond Static files are all the CSS/JS & images that your site (and the django admin) uses. They need to be collected and placed somewhere that your server (or development server) can serve them. This is the job of django.contib.staticfiles. You can read more about this in the 'Managing Static Files' documentation Websites generally need to serve additional files such as images, JavaScript, or CSS. In Django, we refer to these files as “static files”. Django provides django.contrib.staticfiles to help yo

Categories : Django

Django staticfiles and CSS and javaScript
Your CSS files aren't rendered by the Django templating engine, they are just served by your web server, so you can't use the Django template language. If you really wanted to (and this is an exceptionally bad idea) you could serve you CSS files through Django by creating URLs and views that render the CSS files, allowing you to make use of the template language.

Categories : Javascript

In Django, my staticfiles are way to large (over 500K files), how can I divide the load?
You can exclude files and folders: --ignore Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more.

Categories : Python

How to get Django form method to not 500 when debug is false on raising a form error?
call like this def clean(self): password = self.cleaned_data.get('password') email = self.cleaned_data.get('email') user = authenticate(email = email, password = password) if (user is None) or (user is not None and user.is_active is False): raise forms.ValidationError('Login is incorrect.') return self.cleaned_data def login(self,request): user = authenticate(email = self.cleaned_data.get('email'),password = self.cleaned_data.get('password')) user = authenticate(username=username, password=password) return user

Categories : Django

'staticfiles' is not a valid tag library: Template library staticfiles not found
You need to add django.contrib.staticfiles to INSTALLED_APPS Documentation on configuring Static files

Categories : Django

symfony2 : kernel.debug is always false
I guess youre trying to to dump assets using the assetic:dump command. In order to avoid the creation of debug files add --no-debug to the command. you could further execute the command explicitly within the production environment adding --env=prod. So finally ... app/console assetic:dump --env=prod --no-debug ... will not create the debug files. Please note that --no-debug does not work in combination with --watch.

Categories : PHP

Static files won't work if debug = False
For production (that is, DEBUG = False), you need to use the dj-static library as detailed in the official documentation on heroku

Categories : Django

405 (METHOD NOT ALLOWED) for ajax request with django
You have to implement the post method in your view: class SupportView(BaseDetailView): def post(self, request, *args, **kwargs): self.object = self.get_object() context = self.get_context_data(object=self.object) return self.render_to_response(context) Since you didn't define the post method, it's the right behavior to get a 405 (METHOD NOT ALLOWED) error.

Categories : Jquery

When variables not allowed to be null are actually created with no data on Django
First, Avoid using null on string-based fields such as CharField and TextField unless you have an excellent reason (https://docs.djangoproject.com/en/dev/ref/models/fields/#null) The following schema would be generated for your fields in DB event character varying(200), tool character varying(200), other character varying(200) NOT NULL, protocol character varying(200) NOT NULL, This would mean that you can enter "NULL" values in database for 'event' and 'tool' field but not for 'other' and 'protocol' fields. Yet, you can enter a blank text for all the fields irrespective of weather they are "blank=True" or not. Reason being that "Blank=True" is only used by Django for its own validations and its not reflected in Database schema.

Categories : Python

Avoiding Django's 500 error for not allowed host with Nginx
It depends on your default configuration, but from this answer on ServerFault you must define a default vhost in Nginx, otherwise it will use the first one as a default. Basically, your configuration should look like this in order to allow only requests to "mywebsite.com.br" to pass: server { listen 80 default_server; location / { # or show another site return 403 "Forbidden"; } } server { listen 80; server_name mywebsite.com.br; location / { uwsgi_pass unix:/opt/project/run/brmed_web.sock; include uwsgi_params; } } If you need to also serve up other subdomains (www.mywebsite.com.br, etc.) you can set the server_name to ".mywebsite.com.br".

Categories : Django

Restangular remove not working (was: DJANGO: {"detail": "Method 'DELETE' not allowed."})
Answer in original post but includes making sure the ID is returned in the rest services and that the angular factory that encapsulates the restangular resource is done such that the URL can be built dynamically, which includes moving any URL parameters to the request suffix.

Categories : Python

How to set a Django Boolean value to True when by default, it is false?
If you can't or don't want to change the default definition on your model, you can either pass in your desired value when creating your Person instance: newPerson = Person(user = newUser, phoneNum = data['phoneNum'], userPic = data['userPic'], userCover = data['userCover'], suggested_person=True) Or you can set the attribute prior to saving: newPerson.suggested_person = True

Categories : Django

Django model blank=False does not work?
Django creates your user with an empty string. You can actually run Person.objects.all() and it will give you a list, if you save that to a variable called user_list and do something like user_list[0], it will return a user object with an empty string. I do not know how or why it does this.

Categories : Django

Django: how to loop through boolean fields and set all to false
you must return render_to_response('create_order.html', args) one indentation back. so that validation form will not affected. you don't need to use csrf request if you are using render. I think there is no need to use OrderId in Order model, since it is automattically created. ie id from django.shortcuts import render from <appname>.models import Order,Store def create(request): if request.POST: form = OrderForm(request.POST) if form.is_valid(): #i just assume the storeid variable is exist in request.POST and it is ID. store_data=Store.objects.get(id=request.POST['storeid']) #here you might need to update the other orderform to false Order.objects.filter(storeID=store_data).update(Active=False)

Categories : Python

Setting the right URL to make bool false Django
You can set up your urlpatterns like this: urlpatterns = patterns('', url(r'^confirm/(?P<itemnum>d+)/$', 'yourapp.views.confirm', name='confirm-page'), url(r'^deny/(?P<itemnum>d+)/$', 'yourapp.views.deny', name='deny-page'), ) So if user visits http://yourdomain.com/confirm/3/ then it would go to confirm view with itemnum = 3. Similarly if user visits http://yourdomain.com/deny/5/ it would lead to view deny with itemnum = 5

Categories : Python

How to debug Django commands in PyCharm
After installing ipdb (pip install ipdb) put those lines to debug point: import ipdb ipdb.set_trace() https://pypi.python.org/pypi/ipdb

Categories : Django

Best way to implement debug-only middleware in django
You should split your production and local settings to different files, then in your local settings you would just add your middleware. Small example to get you started: File structure: Settings ---> __init__.py ---> prod.py ---> dev.py Example how to add django_debug_toolbar only in dev.py settings: __init__.py: # Other settings ommitted MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ) dev.py: from settings import * # Other settings ommitted MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)

Categories : Django

model definition debug in django
app_label is set to 'backupcenter1', remove it. app_label = 'backupcenter1' means that, as far as Django knows, this model doesn't belong to your application app, but to the backupcenter1 app. Hence why it does not show up in the SQL output for the application app. Also, note that application is a terrible name for an application, you might want to change that.

Categories : Python

How to debug Django templates using PyDev?
PyDev has no custom support for debugging django templates. Still, if you want, you can do something as a breakpoint to check some variable through a template tag. I.e.: In your project create a project/templatetags/pydev_debug.py (that folder also needs the __init__.py) Then add the code to that file: from django import template register = template.Library() @register.filter def pydev_debug(*args): # In pydev, doing pydevd|ctrl+space will show template for pydevd.settrace() # with code below with the proper path to emulate breakpoint. import sys;sys.path.append(r'path/to/eclipse/plugins/org.python.pydev/pysrc') import pydevd;pydevd.settrace() #Emulate breakpoint Then in your template add {% load pydev_debug %} And to get to the breakpoint add {{ my_var|pydev_deb

Categories : Django

How to debug Django unittests with PyDev?
Setup a new debug configuration. Run -> Debug Configurations... Select 'PyDev Django' Click 'New Launch Configuration (top left corner) Name your new configuration Set the project to your project Set the module to your manage.py (browser to your manage.py) Go to the 'Arguments' tab and enter 'test' under 'Program arguments' Click 'Apply' This will allow you to run 'manage.py test' and be able to stop on your breakpoints. Unfortunately, you'll have to create different configurations if you only want to run a subset of tests.

Categories : Python

ico files displayed but not jpg/png, {% load staticfiles %} breaks the code
Your code is correct - url: /image.jpg static_files: image.jpg upload: image.jpg and your images should be "visible" in static directory: - url: /static static_dir: static Just make sure that these declarations are before you reference by package name: - url: .* script: your.app In this case you won't need to {% load staticfiles %}. But your 500 error could be because of using older django versions as before 1.4 it was {% load static %}

Categories : Python

Changing a bool to true/false with URLs in Django
You should change the value of confirmed on the instance of your model and save it: def confirm(request, itemnum): item = get_object_or_404(PurchaseOrder, item_number = itemnum) item.confirmed = True item.save() return HttpResponse('Item number %s changed to true' % itemnum ) Hope that helps.

Categories : Python

Django Form Wizard BooleanFields always returning False
Sorry I gave you the wrong field class. Instead MultipleChoiceField it should be ModelMultipleChoiceField, since you select from models. Something like this works in my case: forms.py (form for first step) class FirstStepForm(forms.Form): def __init__(self, *args, **kwargs): super(FirstStepForm, self).__init__(*args, **kwargs) self.fields['countries'] = forms.ModelMultipleChoiceField(queryset=Country.objects.all()) views.py class MyWizard(SessionWizardView): def render(self, form=None, **kwargs): response = super(MyWizard, self).render(form, **kwargs) grids_data = self.get_cleaned_data_for_step('0') or {} print grids_data return response

Categories : Python

Making a bool stay either true or false in Django
I would handle this using a NullBooleanField, initialize the value to None before confirming or denying, then detect non-None values in the confirm and deny views and provide whatever response you want to give on attempts to change the status. I would probably return a page saying something like "Product %s has already been confirmed" or the like depending on its status, but obviously it depends on your situation. Other solutions are certainly possible - a foreign key to a Status model could be a good idea if you anticipate getting any more complicated.

Categories : Python

Django form with no errors return False for is_valid()
Because you're not passing the arguments into the super call. You should do this: super(MeasureForm,self).__init__(*args, **kwargs) otherwise the form will never actually be initialised with the POST data. Edit after comment The answer to that question didn't recommend removing all the arguments from the super call. If you're passing in measure_id you'll simply need to remove it from kwargs beforehand: def __init__(self, *args, **kwargs): measure_id = kwargs.pop('measure_id', None) super(MeasureForm,self).__init__(*args, **kwargs)

Categories : Django

form.is_valid is false ChoiceField django select in template
You need to specify choices to the form field, otherwise, it will not validate the form. Add something like: CROSSOVER_CHOICES = ( (1.0, "Old value 1.0"), (2.0, "Peak Two"), ) crossover_select = forms.ChoiceField(label="crossover_select", choices=CROSSOVER_CHOICES) Note that, values specified in CROSSOVER_CHOICES should match to the submitted value through form. For that its better to render this field, instead of manually coding choices values in html. So instead of these lines in html <select name="crossover_select"> <option value={{crossover}}>old value {{crossover}}</option> <option value={{peak}}>Peak {{peak}}</option> <option value={{median

Categories : Django

django-rest-framework - trying to set required=False flag on nested 1-to-M?
Checking the Serializer Relation Docs, first you need to add many=True to your cartitems field. Unfortunately this is read-only. The docs just say "For read-write relationships, you should use a flat relational style" — you can find a question about that here (although that's only dealing with the 1-1 case). Current strategies involve making cartitems read-only and then either: doing something post_save, using a second serializer or making a separate request to a separate endpoint to set the related entities. Given that better support for Nested Writes is coming I'd probably be inclined towards a separate request to a separate endpoint for the moment (though that will obviously depend on your constraints). I hope that helps. EDIT: (After update to question & discussion in comment

Categories : Django

django + uwsgi + ngnix + debug off = Server Error (500)
I think it's your ALLOWED_HOSTS setting (new in Django 1.5) Try the following in your settings.py ALLOWED_HOSTS = ['*'] This will allow everything to connect until you get your domain name sorted. It's worth saying that when you do get a domain name sorted make sure you update this value (list of allowed domain names). As the documentation for ALLOWED_HOSTS states: This is a security measure to prevent an attacker from poisoning caches and password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header, which is possible even under many seemingly-safe webserver configurations. Also (a little aside) - I don't know if you have a different setup for your django settings per environment but this is what I do: At the end of your settings

Categories : Django

Show raw SQL in Django with DEBUG=True & for delete() and save()
Make sure you read docs on logging. You need the django.db.backends logger and RequireDebugFalse filter. Example settings: LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' } }, 'handlers': { 'console':{ 'level':'DEBUG', 'filters': ['require_debug_false'], 'class':'logging.StreamHandler', }, }, 'loggers': { 'django.db.backends': { 'handlers':['console'], 'propagate': True, 'level':'DEBUG', }, } } Note: you can also enable SQL query logging in the SQL server configuration, without touching django. Refer to your SQL server documentatio

Categories : Python

How to find value (true or false) from AJAX response?
You're doing things bit too complicated. There's no need of making an array when the response is simply false, as you're already telling the user that the email already exists. Instead of doing if(mysql_num_rows($result)>0){ // email is already exist $phpArray = array("no","Erroremail is aleady exist"); echo json_encode($phpArray); } Just do this in your server side. if(mysql_num_rows($result)>0){ // email is already exist return false; } As you're no longer using an array, your response changes, and you need to adjust your code a little bit. Remove [0] from res[0]. Then your server response will be false, so change if (res[0]=="no"){ return false; } to if (res==false){ return false; } else{ //continue... }

Categories : Javascript

Find which argument is false in "if" in bash script
In general, it's not possible to determine which condition in an && chain failed. But, using a for loop isn't so bad: success=true for f in file1 file2 file3; do if ! [ -f $f ]; then success=false echo "$f is not present" >> logfile fi done if $success; then echo "All three exist" >> logfile fi It also lets you determine if multiple files don't exist, in the event that that information is valuable.

Categories : Bash

Matcher.find() return false android
As commented by somebody else, I would usually use an html parser for extracting stuff from html. However, in your case where you're just pulling a single bit of information out of a string I can see why you want to use a regex. What you need to do is something like this - the issue with your regex was an extra d. Also if you enclose the bit you care about in parenthesis you can grab it using .group. import java.util.regex.*; public class R { public static void main(String[] args){ String Html = "<div class="title">Current Version</div> <div class="content" itemprop="softwareVersion"> 1.1.3 </div> </div> <div class="meta-info"> <div class="title">Requires Android</div> <div class="content" itemprop="operatingSystems"> 2.

Categories : Java

Cannot find a JSP variable in debug mode
NetBeans debugger doesn't see JSP vars as variables that can be evaluated directly. They are context attributes. So, the method that worked for met was to enter pageContext.findAttribute("perspectiveCount") in the "Evaluate Code" tab. After doing so and clicking on "Evaluate Code Fragment" button debugger added pageContext.findAttribute("perspectiveCount") to the "Variables" tab and showed its value there.

Categories : Java

Django returns a strange Internal Server Error even though DEBUG=True
You shouldn't be wrapping a query set in HttpResponse. Take a look at the Django view docs, where there are lots of usage examples: https://docs.djangoproject.com/en/1.5/topics/http/views/

Categories : Python

How to find the end_date of django celery in Django?
If you remember save_db.s will get result of file_transfer.s as first arg. Therefore you can return result from file_transfer.s as tuple with datetime. Example: from django.utils.timezone import now def file_transfer(...): ... return (now(), ...) def save_db(end_date, ...): ...

Categories : Django



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.