Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Cannot connect Nginx with uwsgi +Django
What I've tried: 1. Nginx is fine, can access 80 port and see the default page 2. uwsgi + django is fine, I can use uwsgi to start my django app and access it ,with command: uwsgi --http :8000 --module webapps.wsgi the problem come out when I connect uwsgi to nginx 2017/11/07 01:36:47 [error] 27958#27958: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 71.61.176.181, server: 104.196.31.159, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8001", host: "104.196.31.159:8000" here is the mysite.conf for nginx # mysite_nginx.conf # the upstream component nginx needs to connect to upstream django { #server unix:///home/liuziqicmu/ziqil1/homework/6/mysite.sock; # for a file socket server 127.0.0.1:8001; # for a web port socket (we'll use this first) } # configuration of the server server { # the port your site will be served on listen 8000; # the domain name it will serve for server_name xx.xx.xx.xx(my ip); # substitute your machine's IP address or FQDN charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Django media location /media { alias /home/liuziqicmu/ziqil1/homework6/grumblr/upload; # your Django project's media files - amend as required } location /static { alias /home/liuziqicmu/ziqil1/homework6/static; # your Django project's static files - amend as required … -
max_digits for IntegerField Django
I am looking for a way to specify an IntegerField so that it has a certain maximum of digits. What I'm looking for is similar to max_length of a CharField. I have searched the internet and even in this forum, but they are all answers related to adding minimum and maximum values such as min_length and max_length or adding validators. So that they do not get confused, what interests me is to establish an IntegerField with a maximum of digits and not a maximum value. Is there a function that can provide me so that in the model a parameter can be added to this IntegerField? E.g.: code = models.IntegerField('Code', primary_key=True, max_digits=8) -
How can i restrict date field in Django
im trying to make a Schedulle System using django. I wanna restrict the Date Field(in models.py) for only monday to friday. In sum, i want to restrict saturday and sunday from date field. How can i do that ? -
How can I do datatable filter request in a table using data that comes from another table in Django?
I testing a application that has 2 datatables. I am using django_tables2 and django_filter The first has one button per row, each when it is clicked it should extract a content from the second column of its row and applies this data to request and display the second table bellow considering the filter request. I am quite lost.. How could I do that??? Please any help?? Table.py class MyColumn(tables.Column): empty_values = list() def render(self, value, record): return mark_safe('<button id="%s" class="btn btn-info">Submit</button>' % escape(record.id)) class AdTable(tables.Table): submit = MyColumn() class Meta: model = Ad attrs = {'class': 'table table-striped table-bordered table- hover','id':'id_ad'} class PtTable(tables.Table): class Meta: model = Pt attrs = {'class': 'table table-striped table-bordered table- hover','id':'id_pt'} HTML <body> <div> <h1> "This is the Table" </h1> </div> <div> <table> {% render_table ad_table %} </table> </div> <div> {% block content %} <div> <form method="get"> {{ form.as_p }} <button type="submit">Search</button> </form> </div> {% endblock %} </div> <div> <table> {% render_table pt_table %} </table> </div> <script> $(document).ready(function(){ $('#id_ad').DataTable(); $('#id_ad').on('click','.btn',function(){ var currow = $(this).closest('tr'); var result = currow.find('td:eq(1)').text(); document.getElementById('total').innerHTML = result; }) }); </script> </body> Filter.py class PtFilter(django_filters.FilterSet): class Meta: model = Pt fields = ['var1', 'var2', 'var3', ] Views.py def index(request): ad_table = AdTable(Ad.objects.all()) … -
invalid literal for int() with base 10: '...aa53' - Django
I have a django project and I am trying to save something into my database from a json response. The field in the table is a charfield. the returning response is a string. I want to simply save the response in the database by create a new database object. I am getting the following error an I am not sure why this is happening. invalid literal for int() with base 10: '5..6003463aa53' Here is the code that I have: for node in nodes: node_json = node.json node_id = node_json['_id'] print(node_id) node_name = node_json['info']['nickname'] print(node_name) node_class = node_json['info']['class'] print(node_class) node_bank_name = node_json['info']['bank_name'] final_bank_name = str(node_bank_name) print(node_bank_name) new_account = SynapseAccounts.objects.create( user = currentUser, name = node_name, account_id = node_id, account_class = node_class, bank_name = final_bank_name, ) print(new_account) I even forced the string. Here is the model that I have for the table: class SynapseAccounts(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) name = models.CharField(max_length=100, default='Bank Account') account_id = models.IntegerField(default=0) account_class = models.CharField(max_length=50, default='Checking') bank_name = models.CharField(max_length=150, default='DefaultBank') create = models.DateTimeField(auto_now_add=True) Here is the full stack trace Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner response = get_response(request) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response response = self._get_response(request) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response … -
request.user.attribute returning unwanted value
Why does the following print(owner) return a different value that what's in my model? Is it possible to get the formattedusername defined below? I've simplified my def profile(request) and took out my other arguments till I can figure out the solution to getting formattedusername. def profile(request): owner = User.objects.get (formattedusername=request.user.formattedusername) args = {'user':request.user.formattedusername} print (owner) return render(request, 'accounts/profile.html', args) Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. @HFA9592 [06/Nov/2017 16:18:11] "GET /account/profile/ HTTP/1.1" 200 1416 formattedusername in my model is stored in the database as HCA\HFA9592, it's also defined by the following: class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField(unique=True) username = models.CharField(max_length=7, unique=True) formattedusername = models.CharField(max_length=11, unique=True, primary_key = True) first_name = models.CharField(max_length=40) last_name = models.CharField(max_length=140) date_joined = models.DateTimeField(default=timezone.now) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) facility = models.CharField(max_length=140) jobdescription = models.CharField(max_length=140) positiondescription = models.CharField(max_length=140) coid = models.CharField(max_length=5) streetaddress = models.CharField(max_length=140) USERNAME_FIELD = 'username' class Meta: app_label = 'accounts' db_table = "user" def save(self, *args, **kwargs): self.formattedusername = '{domain}\{username}'.format( domain='HCA', username=self.username) super(User, self).save(*args, **kwargs); -
Django order_by many to many relation
How would one go about ordering a queryset by whether or not a many to many relationship condition is true? i.e. class Publication(models.Model): name = models.CharField(max_length=100) books = models.ManyToManyField(Book) class Book(models.Model): name = models.CharField(max_length=100) author = models.CharField(max_length=100) I would like to make a queryset along the lines of Publication.objects.all().order_by('books__name'='Awesome Book') So that the first items would be the Publication which contains a Book with the title "Awesome Book" and then in the end you have all the Publication's which do not have the book. -
Django/Jinaja2: How to store a dictionary object to a session from a template using a button?
I got a table that acted like a gridview which display fruit and price and also a button that allow the user to store the selected row data (fruit and price) upon clicked on it. For example, if the user clicked on the button of row which contain fruit = apple and price = 1, fruit = apple and price = 1 will be stored in a dictionary variable x and y in fruit_price = {'fruit': x, 'price': y} and finally stored it to a session. Is it possible to do so? result.html <table> <tr> <th>Fruit</th> <th>Price</th> <th>Store to Session</th> </tr> {% for fruit, price in fusion %} <tr> <td>{{ fruit }}</td> <td>{{ price }}</td> <td><button type="button" value="">Store It!</button></td> </tr> {% endfor %} </table> view.py def result(request): ss = request.session.get('store', ?) request.session['store'] = ss data = { 'fruit' : ['apple', 'orange', 'banana'] 'price' : ['1', '2', '3'] } fruit = data['fruit'] price = data['price'] fusion = zip(fruit, price) return render(request, 'result.html', {'fusion' : fusion}) -
Django menu & childmenu from models
I'm trying to a menu system for my sport site project where the sports are grouped together. For example the main category would be "ballsports" and under that (the child menu) people would select football, baseball or whatever else. I've got that all setup and functioning but I can't workout how to call the child menus into the templates. Models: class Sport(models.Model): name = models.CharField(max_length=100, db_index=True) sport_slug = models.SlugField(max_length=100, db_index=True) category = models.ForeignKey('Sport_Category', on_delete=models.CASCADE,) class Sport_Category(models.Model): name = models.CharField(max_length=100, db_index=True) category_slug = models.SlugField(max_length=100, db_index=True) Views: class IndexView(generic.ListView): template_name="sports/index.html" context_object_name='all_sport_category' def get_queryset(self): return Sport_Category.objects.all() def list_of_sports_in_category(self): sport_cat = self.category.name return sport_cat class SportListView(generic.ListView): template_name="sports/sport-home.html" context_object_name='sport_list' def get_queryset(self): return Sport.objects.all() Template: {% for sport_category in all_sport_category %} <li>{{ sport_category.name }} </li> *(Working)* {% for sports in list_of_sports_in_category %} hi {% endfor %} {% endfor %} -
How to make Django-CMS and Open Edx use same authentication for users?
We are looking to develop a Django project in which we need to integrate three different Django packages namely a CMS (Django-CMS or Wagtail), a LMS (Open edX) and a support/ticketing system. Since Django-CMS, Open Edx have their own user authentication, but we want them to share a common authentication (username, password, user profiles), so that a user logged into one section of website is able to move to other sections smoothly. How to make these different packages share same authentication? Is there any guidelines or procedure to integrate these different Django Packages? (Google search about such integration of packages doesnot have any clear documentation, so I decided to ask this on stackoverflow) -
Issue rendering with nested tables in Django
So I'm trying to loop two tables within each other. I have a list of tasks that each have a list of materials. I'd like to next the tables within each other. However, the code below doesn't render the second task into columns. So, when it loops it seems as if the table structure is destroyed. I'm using Django/Python. <div class="table-responsive"> <table id="taskTable" class="table"> {% for task in projecttype.projecttask_set.all %} <h5>Task - {{ task.name }}</h5> <thead class="alert-success"> <tr> <th>Quantity</th> <th>Units</th> <th>Cost</th> </tr> </thead> <tbody> <tr> <td>{{ total_units_required }}</td> <td>{{ task.base_unit_label }}</td> <td>{{ task.base_unit_cost }}</td> </tr> </tbody> <table id="materialTable" class="table"> <thead> <tr class="alert-info"> <th>Material</th> <th>Cost per Task Unit</th> <th>Material Cost</th> <th>Total Cost</th> </tr> </thead> {% for material in task.materials.all %} <tbody> <tr> <td>{{ material.name }}</td> <td>{{ material_quantity_per_task_base_unit }}</td> <td>{{ total_material_quantity }}</td> <td>{{ total_material_cost }}</td> </tr> </tbody> {% endfor %} </table> {% endfor %} </table> </div> enter image description here -
view inheritance from my model
I'm learning Python/Django and i'm trying to do too much, so I'm going to start with the baby steps to figure out my bigger problem. My problem starts with the basic definition of my profile view. def profile(request): args = {'user':request.user} print (request.user) return render(request, 'accounts/profile.html', args) When I review the print it will display as @NHoff. Oddly enough when I view the url for the template, it displays all my user information. My username doesn't have an @ anywhere in it. Although in the pre-existing database i'm working with all data is linked to a domain\username. Which is why i'm unable to link to the pre-existing data. In my AbstractBaseUser model I created formattedusername in the user table using the following: def save(self, *args, **kwargs): self.formattedusername = '{domain}\{username}'.format( domain='HCA', username=self.username) super(User, self).save(*args, **kwargs); How Can I get the formattedusername over into my def profile instead of request.user? formattedusername is the primary key i'd like to use. If that's not possible, how can I force a hardcoded domainname\ prior to my username from request.user. -
machine learning with django
Iam new to machine learning and django.I am trying to implement a machine learning algorithm using django(for UI ). I tried like this In my views.py from django.shortcuts import render from mlapp.models import capgemini from django_pandas.io import read_frame from django.http import HttpResponse import csv from sklearn.linear_model import LinearRegression from sklearn.cross_validation import train_test_split from mlapp.forms import create_capgemini def index1(request): dataReader = open('/home/vishnu/newml/ml4/src/mldata/mlapp/datafiles /mlapp/data.csv', 'r') for row in dataReader: row = row.split(',') capgem=capgemini() capgem.name=row[0] capgem.age=row[1] capgem.number=row[2] capgem.save() dataReader.close() return render(request) def home(request): if request.POST: form = create_capgemini(request.POST) if form.is_valid(): name = form.cleaned_data['name'] age = form.cleaned_data['age'] number = form.cleaned_data['number'] new_developer = capgemini(name=name, age=age, number=number) new_developer.save() else: return render(request, 'mlapp/base.html', {'form' :home}) else: form = create_capgemini() qs=capgemini.objects.all() df=read_frame(qs,fieldnames=['name','age','number']) #print(df) X=df[['age']] y=df[['number']] X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.0) #print(X_train) #print(X_test) #print(y_train) test=capgemini.objects.get(pk=1) test_1 =test.age lm =LinearRegression() lm.fit(X_train,y_train) prediction = lm.predict(test_1) print(prediction) context={'prediction':prediction} #print(lm.coef_) return render(request, 'mlapp/base.html', {'form' :form},context) In forms.py from django import forms class create_capgemini(forms.Form): name = forms.CharField(max_length=100) age =forms.IntegerField() number = forms.IntegerField() In models.py from django.db import models class capgemini(models.Model): name = models.CharField(max_length=100) age = models.IntegerField() number = models.IntegerField() def __unicode__(self): return self.name In base.html <!DOCTYPE html> <html lang="en"> <head> <body> <form method="post" action="{% url "home" %}" > {% csrf_token %} <!-- This line inserts a … -
Django Inline Formset - possible to follow foreign key relationship backwards?
I'm pretty new to django so I apologize if this has an obvious answer. Say you have the following three models: models.py class Customer(models.Model): name = models.CharField() slug = models.SlugField() class Product(models.Model): plu = models.Charfield() description = models.Charfield() class Template(models.Model): customer = models.ForeignKey(Customer) product = models.ForeignKey(Product) price = models.DecimalField() The inline formset would look something like: TemplateFormSet = inlineformset_factory(Customer, Template, extra=0, fk_name='customer', fields=('price')) Is it possible to follow the Template formset's Product foreign key backwards so you could display the plu and description fields within the same table? For example something like this: <table> <tbody> {% for obj in customer.template_set.all %} <tr> <td>{{ obj.product.plu }}</td> <td>{{ obj.product.description }}</td> <td>{% render_field formset.form.price class="form-control form-control-sm" %}</td> </tr> {% endfor %} </tbody> </table> The formset's fields appear with the html above but the data from the bound form instance doesn't appear and I can't save by editing the empty fields. I've also tried below but each formset is repeated for each object (for x formsets there are x*x rows): <tbody> {% for obj in customer.template_set.all %} {% for form in formset %} <tr> <td>{{ obj.product.plu }}</td> <td>{{ obj.product.description }}</td> <td>{% render_field form.price class="form-control" %}</td> </tr> {% endfor %} {% endfor %} </tbody> Basically … -
Iterating through a class to retrieve json response - Synapse/Django
I have a django project and I am trying to integrate SynapsePay Api. I sent a request that returned a class as a response. I am trying to figure out how to cycle or parse the response to get to the json so that I can grab certain values from the response that was returned. I have looked everywhere and cant seem to find a solution or a way to get into a class objects and reach the json part of the return. Here is the response that I am getting... I want to grab the _id from both of the objects returned in the object response below. Does anyone know how I can do this?? [ <class 'synapse_pay_rest.models.nodes.ach_us_node.AchUsNode'>( { 'user':"<class 'synapse_pay_rest.models.users.user.User'>(id=...49c04e1)", 'json':{ '_id':'...639c24', '_links':{ 'self':{ 'href':'https://uat-api.synapsefi.com/v3.1/users/...49c04e1/nodes/...4639c24' } }, 'allowed':'CREDIT-AND-DEBIT', 'client':{ 'id':'...1026a34', 'name':'Charlie Brown LLC' }, 'extra':{ 'note':None, 'other':{ }, 'supp_id':'' }, 'info':{ 'account_num':'8902', 'address':'PO BOX 85139, RICHMOND, VA, US', 'balance':{ 'amount':'750.00', 'currency':'USD' }, 'bank_logo':'https://cdn.synapsepay.com/bank_logos/new/co.png', 'bank_long_name':'CAPITAL ONE N.A.', 'bank_name':'CAPITAL ONE N.A.', 'class':'SAVINGS', 'match_info':{ 'email_match':'not_found', 'name_match':'not_found', 'phonenumber_match':'not_found' }, 'name_on_account':' ', 'nickname':'SynapsePay Test Savings Account - 8902', 'routing_num':'6110', 'type':'PERSONAL' }, 'is_active':True, 'timeline':[ { 'date':1509998865218, 'note':'Node created.' }, { 'date':1509998865962, 'note':'Unable to send micro deposits as node allowed is not CREDIT.' } ], … -
Can't make 1 of the forms not reqired
I've got 2 forms on 1 page, It seems like this: <form method='post' enctype="multipart/form-data" id="formUpload"> {% csrf_token %} {{ image_form }} <button type="submit" class="js-crop-and-upload" name="crop" value="crop">Crop</button> {{ profile_form.as_p }} <button type="submit" class="btn" name="save_profile" value="save_profile">Submit</button> </form> This html form contain ProfileForm for profile data and ImageForm for Profile.image field. I want to save Images clicking button "submit" with name="crop" and save profile clicking button "submit" with name="save_profile". I could easily do this by splitting this html form like this: <form method='post' enctype="multipart/form-data" id="formUpload"> {% csrf_token %} {{ image_form }} <button type="submit" class="js-crop-and-upload" name="crop" value="crop">Crop</button> </form> <form method='post'> {{ profile_form.as_p }} {% csrf_token %} <button type="submit" class="btn" name="save_profile" value="save_profile">Submit</button> </form> But here if I would press submit "crop" - all data in profile form would be deleted. I'm really stuck, because when fill profile fields and press submit with name "save_profile" django tells me that fields from image_form are required and don't send POST to my view, also when some of the fields in profile_form are not filled I couldn't save image using image_form. Also I'm sending my view if this is needed: view: @login_required def profile_new(request): if Profile.objects.filter(user=request.user): return redirect('profile_edit') created_image = Photo.objects.filter(created_by=request.user) if request.method != "POST": profile_form = ProfileForm() image_form … -
Translate Function Success into Function then
I am trying to get django-rest-framework running with angularjs. In order to do the authorization I found django-rest-auth and angular-django-registration-auth Unfortunately the djangoAuth.js is using the depreciated function success within the 'request' variable and I get the following error message: TypeError: $http(...).success is not a function I tried to rewrite the code using the then function, but only end up in the error-Callback. What do I have to change? Thanks for your help. djangoAuth.js - Orginal auth .service('djangoAuth', function djangoAuth($q, $http, $cookies, $rootScope) { // AngularJS will instantiate a singleton by calling "new" on this function var service = { /* START CUSTOMIZATION HERE */ // Change this to point to your Django REST Auth API // e.g. /api/rest-auth (DO NOT INCLUDE ENDING SLASH) 'API_URL': 'localhost:8000/rest-auth', // Set use_session to true to use Django sessions to store security token. // Set use_session to false to store the security token locally and transmit it as a custom header. 'use_session': true, /* END OF CUSTOMIZATION */ 'authenticated': null, 'authPromise': null, 'request': function(args) { // Let's retrieve the token from the cookie, if available if($cookies.token){ $http.defaults.headers.common.Authorization = 'Token ' + $cookies.token; } // Continue params = args.params || {} args = args || … -
Keep div with and image the same height as other div with some text
I'm developing a web page in Django and in it there's a list of the last 5 news that I add with a for loop. The news item has an image on the left, and the title, date and the first 50 words of the news on the right. The image and the text are in separate divs inside another div. I would like to make the image div the same size as the text div, not the other way around. Not all the images have the same dimension. I prefer not to limit the size of the divs with a px value for responsive purposes. I'm using Bootstrap 3.3.7. Here is the Fiddle of what I have now. Is there a way to accomplish this with CSS? -
Unable to install uwsgi with pip on Ubuntu 16.04
I have taken VPS from godaddy and built a machine with Ubuntu 16.04. I want to host a Python (DJango) application. I successfully installed Nginix. Unfortunately, I am not able to install nginix with pip on this machine. When I run sudo pip install uwsgi I am getting the following error. Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-kfJCaG/uwsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-QJoglI-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-kfJCaG/uwsgi/ Please help asap. -
Can't import Django model into scrapy project
I have a folder Project which contains Django project called djangodb and Scrapy project called scrapyspider. So it looks like: Project djangodb djangodb myapp scrapyspider scrapyspider spiders items.py scrapy.cfg __init__.py I want to import model Product from myapp app. The problem is that it returns import error: from Project.djangodb.myapp.models import Product as MyAppProduct ImportError: No module named djangodb.myapp.models Tried many things but couldn't avoid this error. Do you have ideas? -
Django BooleanField doesn't work on edit form
My situation: Models.py class Box(models.Model): is_empty = models.BooleanField(default=False) upload_date = models.DateTimeField(auto_add_now=True) Forms.py class BoxForm(forms.ModelForm): class Meta: model = Box fields = (is_empty,) Views.py def edit_box(request, pk): box = get_object_or_404(Box, pk=pk) if request.method == 'POST': form = BoxForm(request.POST, instance=box) if form.is_valid(): form.save() return redirect('home') else: form = BoxForm(instance=box) return render(request, 'form.html', {'form': form}) The problem is that when I enter into the template form and I want to change checkbox value I can't do it, it seems disabled and I dan't know why. -
ValueError: Cannot query “”: Must be “User” instance
I am trying to create a story-sharing website where user can get to specific author's profile to see all the stories which the author wrote. However I am getting an error. ValueError at /storyauthor/1 Cannot query "yumin": Must be "User" instance. Here is my model class StoryAuthor(models.Model): """ Model representing a author. """ user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True) def get_absolute_url(self): """ Returns the url to access a particular story-author instance. """ return reverse('stories_by_author', args=[str(self.id)]) def __str__(self): """ String for representing the Model object. """ return self.user.username -
Method Not Allowed (POST) using DeleteView
I am new to Django and i using Class based views to add a delete option to my Restaurant List, However when i click the delete button i am getting a blank screen and getting the following error in the console "Method Not Allowed (POST):" Below is my code views.py from __future__ import unicode_literals from django.db.models import Q from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render, get_object_or_404 from django.views import View from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import TemplateView, ListView, DetailView, CreateView,DeleteView from django.urls import reverse_lazy class RestaurantDeleteView(DeleteView): model = RestaurantLocation success_url = reverse_lazy('restaurants:list') urls.py from django.conf.urls import url, include from .views import ( RestaurantListView, RestaurantDetailView, RestaurantCreateView, RestaurantDeleteView, ) urlpatterns = [ url(r'^create/$', RestaurantCreateView.as_view(), name= 'create'), url(r'^$',RestaurantListView.as_view(), name= 'list'), url(r'^(?P<slug>[\w-]+)/$',RestaurantDetailView.as_view(), name="detail"), url(r'^(?P<slug>[\w-]+)/delete/$', RestaurantDeleteView.as_view(), name="restaurant-delete"), ] delete.html <form method="t" action="" >{% csrf_token %} <p>Are you sure you want to delete <strong> {{ obj }}</strong>?</p> <input type="submit" value="DELETE" /> </form> -
Using SQLite on AWS EB: no such table django_session
In my django app with the standard folder structure I have created an .ebignore file with the following content: # SQLite db.sqlite3 The purpose is that when I deploy to AWS EB my SQLite database won't get overwritten. I want to keep the SQLite database on my server unchanged when I modify my app. However, after I deploy ('eb deploy') and I visit the /admin url of my website I get the following error: no such table: django_session What's the correct way to re-deploy to AWS without overwriting the SQLite database? -
Django no reverse match at /
I'm trying to make a picture the url to the post the picture represents, and I must be doing something wrong, but I don't know what. I am getting this error when trying to visit the home page of my site. Error during template rendering In template .../home.html, error at line 48 Reverse for 'view_post' with keyword arguments '{'post_id': ''}' not found. 1 pattern(s) tried: ['post/(?P[0-9]+)/$'] and the code it showcases <a href="{% url 'view_post' post_id=post.post_id %}"><img src="media/{{ item.image }}"></a> Also this is my view def view_post(request, post_id): post = get_object_or_404(Post,id=post_id) return render(request,'gram/view_post.html',{'post': post}) And url url(r'^post/(?P<post_id>[0-9]+)/$', views.view_post, name='view_post'), Thank you for your help.