Django – what is the difference between render(), render_to_response() and direct_to_template()?

https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render render(request, template[, dictionary][, context_instance][, content_type][, status][, current_app]) render() is a brand spanking new shortcut for render_to_response in 1.3 that will automatically use RequestContext that I will most definitely be using from now on. 2020 EDIT: It should be noted that render_to_response() was removed in Django 3.0 https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render-to-response render_to_response(template[, dictionary][, context_instance][, mimetype])ΒΆ render_to_response is your … Read more

How can I save my secret keys and password securely in my version control system?

You’re exactly right to want to encrypt your sensitive settings file while still maintaining the file in version control. As you mention, the best solution would be one in which Git will transparently encrypt certain sensitive files when you push them so that locally (i.e. on any machine which has your certificate) you can use … Read more

ValueError at /image/ Tensor Tensor(“activation_5/Softmax:0”, shape=(?, 4), dtype=float32) is not an element of this graph

Your test_image and input of tensorflow model is not match. # Your image shape is (, , 3) test_image = cv2.imread(‘media/’+request.FILES[‘test_image’].name) if test_image is not None: test_image = cv2.resize(test_image, (128, 128)) test_image = np.array(test_image) test_image = test_image.astype(‘float32’) test_image /= 255 print(test_image.shape) else: print(‘image didnt load’) # Your image shape is (, , 4) test_image = … Read more

django installation: cannot use pip to install django on linux(ubuntu)

Don’t use sudo use a virtual environment instead, like this: $ sudo apt-get install python-virtualenv $ mkvirtualenv django_env $ source django_env/bin/activate (django_env) $ pip install django (django_env) $ cd $HOME (django_env) $ mkdir projects (django_env) $ cd projects (django_env)/projects $ django-admin.py startproject foo (django_env)/projects $ cd foo (django_env)/projects/foo $ python manage.py runserver When you are … Read more

What is the right way to use angular2 http requests with Django CSRF protection?

Now that Angular 2 is released the following seems to be the correct way of doing this, by using CookieXSRFStrategy. I’ve configured my application to have a core module but you can do the same in your main application module instead: import { ModuleWithProviders, NgModule, Optional, SkipSelf } from ‘@angular/core’; import { CommonModule } from … Read more

Forbidden (403) CSRF verification failed. Request aborted. Even using the {% csrf_token %}

Theory A couple of things are required to make the csrf protection work (check out the docs): Your browser has to accept cookies from your server Make sure you have ‘django.middleware.csrf.CsrfViewMiddleware’ included as middleware in your settings.py (alternatively use the decorator csrf_protect() on particular views you want to protect) Make sure you pass on the … Read more