Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
How to keep out utility functions in a separate directory inside an app in Django
In my current project, I have moved out most of the business logic from my views and have put them under the following directory structure myapp/utility/utility.py. Under the Utility directory i have put the init.py file also. I am using most of the models from my Models.py file in the utils.py file. Now the problem I am facing is when I run python manage.py runserver, it throws up an error saying models not found. I had also followed the steps listed in the Django docs here -
How to implement a temporary password logic for websites?
I want to implement a logic for my website where I want to generate temporary password for the people who visit my website. The password should expire once the person logs out. How do I write the logic for this. I want to implement it using django and python. Someone please suggest. -
Need advice on implementing an app using Django
I have a simple python app and I need to know what is the best practice to turn it into a Django app. My app is something like this: Class abc(): #some attributes A=[6,7,6,4,3] B=[6,8,9,[7,1,1000]] #some methods Def aaa(self): #do something on A and B Return something Def bbb(self): ###do something using previous methods and attributes Return something X=abc() X.bbb() I already know how to turn classes into django models, but the twist is: 1) Most of those attributes are long lists of lists 2) Methods return lists which then gets used in other methods 3) I also need advice on how to get user input for those list of lists (formsets maybe, but how?) -
Unable to load the SpatiaLite library extension "mod_spatialite" due to undefined symbol: libiconv
I trying to deploy a Django application (python 2.7), which use Spatialite as a db backend. When I try to make migrations I get this error: vagrant@ubuntu-xenial:~/geospaas_doppler$ python manage.py makemigrations Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute() File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options) File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 110, in handle loader.check_consistent_history(connection) File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/db/migrations/loader.py", line 282, in check_consistent_history applied = recorder.applied_migrations() File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations self.ensure_schema() File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()): File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 254, in cursor return self._cursor() File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 229, in _cursor self.ensure_connection() File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection self.connect() File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 189, in connect self.connection = self.get_new_connection(conn_params) File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/base.py", line 65, in get_new_connection six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2]) File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/contrib/gis/db/backends/spatialite/base.py", line 60, in get_new_connection cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,)) File "/home/vagrant/miniconda/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute return Database.Cursor.execute(self, query, params) django.core.exceptions.ImproperlyConfigured: Unable to load the SpatiaLite library extension "mod_spatialite" because: /home/vagrant/miniconda/lib/././mod_spatialite.so: undefined symbol: libiconv Searching of a solution in the web as well as instlation of the libiconv did not help. The OS is … -
Django - problems with static files when running in subpath
I have django app running in subpath example.com/api/. Most of it is rest API (I use django-rest-framework), and all requests are working correctly. But static files has wrong paths everywhere - in admin panel, and in requests page (in django-rest-framework you have frontend to investigate things). Django somehow thinks, that all static files are in example.com/back/static/, when they are in example.com/api/back/static/. Also example.com/api/admin redirects to example.com/admin/login/, but after manually going to example.com/api/admin/login/ everything works smoothly (but still there are no styles). My stack is nginx + Django 2.0.5 running in docker container. Nginx configuration: location /api/ { proxy_pass http://localhost:8000/; proxy_read_timeout 90; proxy_connect_timeout 90; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Proxy ""; } ` When it comes to Django STATIC_URL is set to os.path.join(BASE_DIR, "static/"), FORCE_SCRIPT_NAME is not set, but when set, it's not working at all. Any ideas? -
How can an API accept several requests and run at the same time using tornado framework in python?
I want to get many images using their name and url in json format, like this one: { "imagesInfo":[ { "url":"https://upload.wikimedia.org/wikipedia/commons/b/ba/Flower_jtca001.jpg", "fileName": "A", } ] } And download them from url and save the images in my image server, but when it accepts a request and runs it, can't run other requests at the same time and blocks them until the first request finishes.I need to change the code so that it can accept requests and run them parallel,I use tornado framework which is asynchronous as it is said in its documents, and I used @tornado.gen.coroutine but it didn't worked.I don't want to use process pool and thread pool since I tested them before and it takes all of my server resources and stops running.here is my FileHandler: class FileHandler(BaseHandler): @tornado.gen.coroutine def prepare(self): self.request.body = self.request.body.decode('utf-8') self.json_args = json.loads(self.request.body) @tornado.gen.coroutine def post(self ,arg): if arg == "bulkImageImport": save_instance=SaveImage() yield save_instane.save_image(self.json_args['imagesInfo']) self.finish("done") and this is app.py file that runs for different routes: (ImageRoute is a class which different routes are defined there.) def make_app(): return tornado.web.Application([(r"/", MainHandler), (ImageRoute.BLOB_IMAGE, imageHandler.ImageHandler), (ImageRoute.BULK_IMAGE_IMPORT, FileHandler.FileHandler),]) if __name__ == "__main__": app = make_app() app.listen(config.PORT) tornado.ioloop.IOLoop.current().start() If I change the framework to django,does it solve the problem? … -
Can I do a django get latest where ==
I already have a function to get latest by date foo.objects.latest('date_added').itemName I want to know if it is possible some something similar but with an added where like if I have type a, b or c I want to get the latest by date_added where it is type c for instance. -
Manager isn't available; 'auth.User' has been swapped for 'users.CustomUser'
I'm getting this error when trying to do sign up operation in django 1.11 some fields are also not showing up. i've tried using import get_user_model but still does not work. help me out please models.py from django.db import models from django.contrib.auth.models import AbstractUser # from django.contrib.auth import get_user_model # User = get_user_model() class CustomUser(AbstractUser): # First/last name is not a global-friendly pattern name = models.CharField(blank=True, max_length=255) domain = models.CharField(blank=True, max_length=255) def __str__(self): return self.email my forms.py from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm from users.models import CustomUser from django.contrib.auth import get_user_model User = get_user_model() class CustomUserCreationForm(UserCreationForm): class Meta(UserCreationForm.Meta): model = CustomUser fields = ('username', 'email') class CustomUserChangeForm(UserChangeForm): class Meta: model = CustomUser fields = UserChangeForm.Meta.fields my views.py from django.contrib.auth.forms import UserCreationForm from django.core.urlresolvers import reverse_lazy from django.views import generic from django.contrib.auth import get_user_model User = get_user_model() class SignUp(generic.CreateView): form_class = UserCreationForm success_url = reverse_lazy('login') template_name = 'signup.html' in setting.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'accounts', 'users' ] AUTH_USER_MODEL = 'users.CustomUser' please tell me where i'm wrong. -
uWSGI + Django: ImportError: No module named 'wsgi'
My project structure: /srv/venv is the home of virtualenv (contains directories like bin or lib) /srv/venv/webapp is the home of the Django application and contains the file wsgi.py My .ini file: [uwsgi] plugins = python chdir = /srv/venv/webapp module = wsgi home = /srv/venv/ master = true processes = 10 socket = /tmp/srv.sock chmod-socket = 666 vacuum = true buffer-size = 32767 die-on-term = true Upon startup, uWSGI says: Wed Jul 4 10:58:40 2018 - chdir() to /srv/venv/webapp Wed Jul 4 10:58:40 2018 - Set PythonHome to /srv/venv/ ImportError: No module named 'wsgi' And every request ends up with: Wed Jul 4 10:28:45 2018 - --- no python application found, check your startup logs for errors --- [pid: 643|app: -1|req: -1/1] 192.168.33.1 () {42 vars in 653 bytes} [Wed Jul 4 10:28:45 2018] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0) When I do cd /srv/venv/webapp, run python and type import wsgi, no errors happen. Any ideas what might be wrong? -
Restrict mobile devices to see some items
I'm developing a Django application and I am using django_user_agents but when I load {% load user_agents %} at the beginning of the html and when I want to restrict something to be visible only for pc users like that {% if request.user_agent.is_pc %} it does not show it either on pc and mobile. Can somebody tell me what I'm doing wrong? For example {% if request.user_agent.is_pc %} <a href="javascript:;" style="top:5px;left:95px;position:absolute;display:inline-block;padding:10px;background:#eee;border:1px solid #333;" onclick="eraseCookie('theme');window.location.reload();"></a> <a href="javascript:;" style="top:30px;left:95px;position:absolute;display:inline-block;padding:10px;background:#333;border:1px solid #eee;" onclick="createCookie('theme','dark',365);window.location.reload();"></a> {% endif %} It id not displaying on a pc browser as well as on mobile browsers Thank you in advance, this is my firts Django app and I really don't know how to do that -
Change color of row in admin page
I want to change the color of those rows in admin page whose valid_until field (in model class) is less than specific_date field (in model class). How should I proceed with this? -
Cannot push django app to Heroku
I am trying to deploy a CMS application on Heroku. But when I try git push heroku master I am getting the following errors. Counting objects: 2841, done. Delta compression using up to 4 threads. Compressing objects: 100% (2775/2775), done. Writing objects: 100% (2841/2841), 13.35 MiB | 497.00 KiB/s, done. Total 2841 (delta 917), reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Python app detected remote: -----> Installing python-3.6.6 remote: -----> Installing pip remote: -----> Installing requirements with pip remote: Collecting pkg-resources==0.0.0 (from -r /tmp/build_2e9a3f2d21d5a1b3c5ab348811182510/requirements.txt (line 1)) remote: Could not find a version that satisfies the requirement pkg-resources==0.0.0 (from -r /tmp/build_2e9a3f2d21d5a1b3c5ab348811182510/requirements.txt (line 1)) (from versions: ) remote: No matching distribution found for pkg-resources==0.0.0 (from -r /tmp/build_2e9a3f2d21d5a1b3c5ab348811182510/requirements.txt (line 1)) remote: ! Push rejected, failed to compile Python app. remote: remote: ! Push failed remote: Verifying deploy... remote: remote: ! Push rejected to peaceful-olympic-84671. remote: To https://git.heroku.com/peaceful-olympic-84671.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/peaceful-olympic-84671.git' I have already seen many answers to this same question on stack overflow but none of the answers is working for me. Please help. -
Django Middleware/Domain Redirects: http to https ignoring full path
So I've written a Django Middleware to redirect from example.com to www.example.com and also redirect from http to https. I thought everything was working fine, until I tried to access pages with the following URLS: http://example.com/subpage redirects to https://www.example.com/ (add https correctly but ignore path) So trying to access a subpage on the site without the www always redirects to https but ignores path, and redirects to homepage. https://example.com/ (or any https request without the www) just hangs. So trying to access the site with https but without the www, simply hangs. trying to access the site without https and without www works fine, but again, redirects to homepage. In addition to the middleware below, I have Namecheap set up to redirect domains, like so. Middleware: from django.shortcuts import redirect from django.core.exceptions import MiddlewareNotUsed from django.conf import settings from django.utils.deprecation import MiddlewareMixin SITE_DOMAIN = "www.example.com" class CanonicalDomainMiddleware(object): def __init__(self, get_response): self.get_response = get_response if settings.DEBUG or not SITE_DOMAIN: raise MiddlewareNotUsed # One-time configuration and initialization. def __call__(self, request): """If the request domain is not the canonical domain, redirect.""" hostname = request.get_host().split(":", 1)[0] print(f'hostname is {hostname}') print(f'request full path is {request.get_full_path()}') # Don't perform redirection for testing or local development. if … -
Pandas not importing excel changes
I am working in a python/django project in which I import some data from an Excel file. The simplified view in which I need the import is: urls.py re_path(r'^product_push/', sick_data_views.Products_List_upload, name='product-push') views.py def ID_push(): Products.objects.all().delete() df = product.importDataFrameProducts() print(df) data = Products( ID = str(df['ID'].tolist()).replace("'",'\"'), ) data.save() def Products_List_upload(request): ID_push() return HttpResponse(status=204) models.py class Products(models.Model): ID = models.CharField(max_length=1000000) lists.py class product: def __init__(self, excel_path = os.path.dirname(os.path.realpath(__file__))+"\\A_Products.xlsx"): self.__df = self.importDataFrameExamplesList(excel_path) def importDataFrameExamplesList(self, excel_path): # Load json df = pd.read_excel(excel_path, keep_default_dates=False) return df def importDataFrameProducts(self): return self.__df When I run the server, the importation process runs and I get the correct output: The views call lists.py and updates the values. Let's say: ID 1 2 3 But if I change the Excel file to other values, like: ID 4 2 3 If I run localhost:8000/product_push, the importation return the older values of the Excel file (1,2,3). I don't need to update automatically, but when I run the push url, I should be able to get the updated values. Does panda store some variable in cache? Because I can only solve this problem after I rerun the server. Thanks in advance. -
Get_queryset() missing 1 required positional argument: 'request'
I have a listview like this: class IncidentListView(generic.ListView): model = Incident paginate_by = 3 def get_queryset(self,request): order_by = request.GET.get('order_by', 'defaultOrderField') return model.objects.all().order_by(order_by) When I go to the url, I get this error: get_queryset() missing 1 required positional argument: 'request' What am I doing wrong? I want to make it so you can click a sorting link that creates a new listview, but unsure how to approach. For reference, I followed the recommendation here -
How to effectively interact with a SQL database from python using a django-like structure?
Is there any Django like python package that would allow interaction with a MySQL database through a powerful structure (like models, managers, querysets, ...)? I'm looking for something that would handle relations nicely like Django but connecting directly to the MySQL server, without having a full structure around. -
Templatetags on Flatpages
I'm trying to output a resulting string as HTML but the flatpage app renders it as a string. I realized that the assignment_tag decorator is deprecated for Django 2.0+. However, if I use an alias to the custom template_tag, the value won't show up (if I don't use an alias, it shows up as a string). What could I be missing? I've tried {{ var | safe }} to no avail. Here's how it looks templatetags/section_links_tags.py: from django import template from django.contrib.flatpages.models import FlatPage register = template.Library() @register.simple_tag() def get_result_tag(id): get_flat = FlatPage.objects.get(id=id) sections_1 = {"Key 1": "Value 1", "Key 2": "", "Key 3": "Value 3", "Key 4": "Value 4"} sections = [] iterator = [] if get_flat.id == 1: for key, value in sections_1.items(): iterator = '<li><a href="' + value + '">' + key + '</a></li>' sections.append(iterator) else: sections = '<li><a href="none">SECTION</a></li>' return ''.join(sections) flatpages/default.html: {% extends "my_app/base.html" %} {% block title %} {{ flatpage.title }} - {{ block.super }} {% endblock %} {% load section_links_tags %} {% get_result_tag "flatpage.id" as section %} {% block content %} <section class="container"> <div class="row"> <div id="faq_toc"> <h3>Table of Contents</h3> <ul class="list-unstyled text-right"> <li><a href="#list1">List 1</a></li> <li><a href="#list2">List 2</a></li> <li><a href="#main">Main Content</a> <ol> … -
Django: Update/edit populated form and formset
Can someone help me answering why my update view function doesn't run? It returns populated form and formset with no error messages (and without file attachments). This happened after updating the function with a formset (made with modelformset_factory): def recipe_update(request, id=None): if request.method == 'GET': instance = get_object_or_404(Recipe, id=id, user=request.user) form = RecipeForm(request.POST or None, request.FILES or None, instance=instance) formset = IngredientModelFormset(queryset=Ingredient.objects.filter(recipe=instance)) elif request.method == 'POST': instance = get_object_or_404(Recipe, id=id, user=request.user) form = RecipeForm(request.POST, request.FILES or None) formset = IngredientModelFormset(request.POST, request.FILES or None) if form.is_valid() and formset.is_valid(): recipe = form.save() for forms in formset: ingredient = forms.save(commit=False) ingredient.recipe = recipe ingredient.save() return redirect(recipe.get_absolute_url()) context = { "instance": instance, "form": form, 'formset': formset, } return render(request, "recipes/recipe_form.html", context) The create function is working correctly: def recipe_create(request): if request.method == 'GET': form = RecipeForm(request.POST or None, request.FILES or None) formset = IngredientModelFormset(queryset=Ingredient.objects.none()) elif request.method == 'POST': form = RecipeForm(request.POST, request.FILES or None) formset = IngredientModelFormset(request.POST, request.FILES or None) if form.is_valid() and formset.is_valid(): recipe = form.save() for forms in formset: ingredient = forms.save(commit=False) ingredient.recipe = recipe ingredient.save() return redirect(recipe.get_absolute_url()) context = { "form": form, 'formset': formset, } return render(request, "recipes/recipe_form.html", context) Thanks a lot! -
'AttributeError' : Object has no attribute 'get'
error : AttributeError at / 'UserForm' object has no attribute 'get' I am not able to debug this error! I overlooked my codes many times, but cant able to understand where is the error being generated.Please be helping me. Thanks in advance. froms.py class UserForm(forms.Form): username = forms.CharField() email = forms.EmailField() password1 = forms.PasswordInput() password2 = forms.PasswordInput() def clean(self): password1 = self.cleaned_data['password1'] password2 = self.cleaned_data['password2'] if password1 != password2: raise forms.ValidationError('Password Should Match') return self.cleaned_data views.py def userview(request): if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] email = form.cleaned_data['email'] password1 = form.cleaned_data['password1'] user = User(username=username,email=email,password =password1) user.save() return HttpResponse('User Created') else: form = UserForm() return render(request,'home.html',{'form':form}) template home.html <form method="post" id="post-form"> {% csrf_token %} {{form.as_p}} <input type='submit' value ='ok'> </form> -
django_apscheduler.models.DoesNotExist: DjangoJob matching query does not exist
hi I am trying to implement a job scheduler using djangorestframework , django-apscheduler and requests libraries but when I try to post a request for scheduling a job following error appear although job is scheduled but response is code Internal server error (500) with following error Traceback (most recent call last): File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner response = get_response(request) File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, **kwargs) File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/django/views/generic/base.py", line 69, in view return self.dispatch(request, *args, **kwargs) File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch response = self.handle_exception(exc) File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception self.raise_uncaught_exception(exc) File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch response = handler(request, *args, **kwargs) File "/Users/gauravyadav/Python/env4/Scheduler3/distribute_jobs/views.py", line 298, in post scheduler.start() File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/apscheduler/schedulers/blocking.py", line 19, in start self._main_loop() File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/apscheduler/schedulers/blocking.py", line 30, in _main_loop wait_seconds = self._process_jobs() File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/apscheduler/schedulers/base.py", line 987, in _process_jobs jobstore_next_run_time = jobstore.get_next_run_time() File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/django_apscheduler/jobstores.py", line 29, in inner return func(*a, **k) File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/django_apscheduler/jobstores.py", line 79, in get_next_run_time return //not able to ident this code deserialize_dt(DjangoJob.objects.filter(next_run_time__isnull=False).earlie s .t('next_run_time').next_run_time)/// File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/django/db/models/query.py", line 597, in earliest return self._earliest_or_latest(*fields, field_name=field_name) File "/Users/gauravyadav/Python/env4/lib/python3.6/site-packages/django/db/models/query.py", line 594, in _earliest_or_latest return … -
django call multiple models
i'm study bioinformatics i want to make django DataBase i already know make model, it has three columns. i Meet a big huddle making models my db has too many columns(about 700) from django.db import models class CMS(models.Model): class Meta: db_table = 'CMS' AT1G01560.3 = models.CharField(max_length=20) AT1G01560.2 = models.CharField(max_length=20) AT1G01610.1 = models.CharField(max_length=20) AT1G01720.1 = models.CharField(max_length=20) . . . . . . . . . . . . AT5G66280.1 = models.CharField(max_length=20) I could not write all 700 then, i call DataFrame and i use DataFrame.columns import pandas as pd from django.db import models # Create your models here. class CMS(models.Model): class Meta: db_table = 'cms' df=pd.read_csv('UDUBBBBBBBBBBB.csv',sep='\t') db_columns=df.columns for xx in df.columns: k= models.CharField(max_length=20) exec("%s=%s"%(xx,k)) but its has error target_id,AT1G01560.3,AT1G01560.2,AT1G01610.1,AT1G01720.1,AT1G02110.1,AT1G02220.1,AT1G02230.1,AT1G02440.1,AT1G02450.1,AT1G03430.1,AT1G03850.3,AT1G03850.2,AT1G06000.1,AT1G06160.1,AT1G06620.1,AT1G06620.2,AT1G06640.1,AT1G06640.3,AT1G06640.2,AT1G06980.1,AT1G07630.1,AT1G08050.1,AT1G09310.1,AT1G09630.1,AT1G09750.1,AT1G10417.4,AT1G11310.3,AT1G11440.1,AT1G11580.1,AT1G11700.1,AT1G12010.1,AT1G12240.1,AT1G13470.1,AT1G13540.1,AT1G13550.1,AT1G14120.3,AT1G14130.1,AT1G14250.1,AT1G14700.2,AT1G16670.1,AT1G17380.2,AT1G17380.3,AT1G17840.1,AT1G18650.1,AT1G19180.3,AT1G19300.1,AT1G19550.1,AT1G19570.1,AT1G19670.1,AT1G20190.1,AT1G21130.2,AT1G23050.1,AT1G23330.1,AT1G23830.1,AT1G23840.1,AT1G23850.1,AT1G24070.1,AT1G24070.2,AT1G24145.1,AT1G25230.1,AT1G28480.1,AT1G28510.1,AT1G28600.1,AT1G29330.1,AT1G29430.1,AT1G29440.1,AT1G29450.2,AT1G29500.1,AT1G29510.1,AT1G29660.1,AT1G29670.1,AT1G30900.1,AT1G31550.1,AT1G31550.2,AT1G32640.1,AT1G32690.1,AT1G33612.1,AT1G34750.1,AT1G34750.4,AT1G43160.1,AT1G43310.1,AT1G44790.1,AT1G45145.1,AT1G45201.1,AT1G47840.1,AT1G49320.1,AT1G49490.1,AT1G51760.1,AT1G51780.1,AT1G51860.2,AT1G52030.1,AT1G52190.1,AT1G52400.1,AT1G52400.2,AT1G52410.2,AT1G52410.1,AT1G52720.1,AT1G53250.1,AT1G53885.1,AT1G53903.1,AT1G54010.1,AT1G54020.2,AT1G54030.2,AT1G54040.3,AT1G54740.1,AT1G55910.1,AT1G56020.1,AT1G58300.1,AT1G60260.1,AT1G60800.2,AT1G61065.1,AT1G61120.1,AT1G61610.1,AT1G62520.1,AT1G62660.1,AT1G62660.4,AT1G64200.2,AT1G64200.1,AT1G64710.1,AT1G64710.2,AT1G65890.1,AT1G66100.1,AT1G66880.3,AT1G67330.1,AT1G67590.1,AT1G67750.1,AT1G68190.1,AT1G68330.1,AT1G68780.1,AT1G69370.1,AT1G69520.1,AT1G69610.1,AT1G70690.1,AT1G70700.1,AT1G70700.3,AT1G70700.2,AT1G71040.1,AT1G71100.1,AT1G72120.1,AT1G72450.2,AT1G72645.1,AT1G72730.1,AT1G72900.1,AT1G72920.1,AT1G73325.1,AT1G73500.1,AT1G73805.1,AT1G73830.1,AT1G74950.2,AT1G74950.1,AT1G75220.1,AT1G75250.2,AT1G75990.1,AT1G77420.1,AT1G77450.1,AT1G77520.1,AT1G77885.1,AT1G78170.1,AT1G78270.1,AT1G78450.1,AT1G78490.1,AT1G78550.1,AT1G78560.1,AT1G78660.3,AT1G78660.2,AT1G79310.1,AT1G79380.1,AT1G79760.1,AT1G80510.1,AT1G80610.1,AT2G02310.1,AT2G02800.2,AT2G02800.1,AT2G03980.3,AT2G04515.1,AT2G05260.1,AT2G05310.2,AT2G06255.1,AT2G10940.2,AT2G13790.1,AT2G14560.3,AT2G15090.1,AT2G17120.1,AT2G20340.1,AT2G21900.1,AT2G22200.1,AT2G22770.1,AT2G22860.1,AT2G23010.1,AT2G23560.1,AT2G24210.1,AT2G24850.1,AT2G26390.1,AT2G26400.2,AT2G26400.1,AT2G26740.1,AT2G27130.1,AT2G27310.1,AT2G27385.1,AT2G27660.1,AT2G27690.1,AT2G28400.1,AT2G28890.1,AT2G29290.1,AT2G29290.2,AT2G29300.1,AT2G29310.2,AT2G29450.1,AT2G29710.1,AT2G29750.1,AT2G30100.1,AT2G30360.1,AT2G30550.2,AT2G30830.1,AT2G32090.1,AT2G32160.2,AT2G32380.1,AT2G32487.2,AT2G32487.3,AT2G32510.1,AT2G33780.1,AT2G34180.1,AT2G34490.1,AT2G34600.1,AT2G34810.1,AT2G34940.1,AT2G35000.1,AT2G35960.1,AT2G36330.1,AT2G36380.1,AT2G37620.2,AT2G37710.1,AT2G37790.1,AT2G37950.1,AT2G38400.1,AT2G38400.2,AT2G38750.1,AT2G38760.1,AT2G39030.1,AT2G39330.3,AT2G39420.1,AT2G39770.2,AT2G40530.1,AT2G40750.1,AT2G41660.1,AT2G41835.1,AT2G41990.1,AT2G42760.1,AT2G42900.1,AT2G43520.1,AT2G43530.1,AT2G43535.1,AT2G43550.1,AT2G44578.1,AT2G44840.1,AT2G45010.1,AT2G45930.1,AT2G46100.1,AT2G46100.2,AT2G46400.1,AT2G46510.1,AT2G47130.1,AT3G01513.1,AT3G01930.2,AT3G02230.1,AT3G02510.1,AT3G02570.1,AT3G03480.1,AT3G03820.1,AT3G03840.1,AT3G04480.1,AT3G05830.1,AT3G06130.1,AT3G07010.1,AT3G07500.1,AT3G07540.1,AT3G09010.1,AT3G09010.2,AT3G09035.1,AT3G09260.1,AT3G09490.1,AT3G10260.1,AT3G11010.1,AT3G11340.1,AT3G11402.1,AT3G12145.1,AT3G12610.1,AT3G14050.1,AT3G14840.2,AT3G15570.1,AT3G15760.1,AT3G15790.1,AT3G15950.1,AT3G16250.1,AT3G16370.1,AT3G16400.2,AT3G16420.1,AT3G16420.3,AT3G16460.1,AT3G16470.1,AT3G16470.2,AT3G17640.1,AT3G17810.1,AT3G17860.1,AT3G18000.1,AT3G18050.1,AT3G18710.1,AT3G19000.1,AT3G19580.1,AT3G19850.1,AT3G20390.1,AT3G20600.1,AT3G20820.1,AT3G21220.2,AT3G21640.1,AT3G22160.1,AT3G22760.2,AT3G22960.1,AT3G23880.1,AT3G25070.1,AT3G25670.1,AT3G25700.1,AT3G25760.1,AT3G25770.1,AT3G25780.1,AT3G25882.1,AT3G26200.1,AT3G26210.1,AT3G26450.1,AT3G26690.1,AT3G28220.1,AT3G28480.1,AT3G28550.1,AT3G28740.1,AT3G29240.2,AT3G29240.1,AT3G29400.1,AT3G44190.1,AT3G44720.1,AT3G44860.1,AT3G44940.1,AT3G45140.1,AT3G45140.2,AT3G46640.2,AT3G46700.1,AT3G47050.1,AT3G47090.1,AT3G47820.1,AT3G48350.1,AT3G48640.2,AT3G50280.1,AT3G50440.1,AT3G50470.1,AT3G50760.1,AT3G50800.1,AT3G51090.1,AT3G51350.1,AT3G51450.1,AT3G51890.1,AT3G51910.1,AT3G52430.1,AT3G52470.1,AT3G52910.1,AT3G55110.1,AT3G55250.1,AT3G55970.1,AT3G55970.2,AT3G56400.1,AT3G56710.1,AT3G56710.2,AT3G57460.1,AT3G57480.2,AT3G57700.1,AT3G58070.1,AT3G59050.1,AT3G60220.1,AT3G60420.1,AT3G61920.1,AT3G62420.1,AT3G62750.7,AT3G63440.1,AT4G00400.1,AT4G00500.1,AT4G00955.1,AT4G01070.1,AT4G01080.1,AT4G01370.1,AT4G01460.1,AT4G01580.1,AT4G02220.1,AT4G02360.1,AT4G02380.3,AT4G03070.1,AT4G03190.1,AT4G04630.1,AT4G04695.1,AT4G04900.1,AT4G06744.1,AT4G08685.1,AT4G08870.1,AT4G09560.1,AT4G10120.5,AT4G10290.1,AT4G10390.1,AT4G11000.1,AT4G11310.1,AT4G11320.1,AT4G11320.2,AT4G11911.1,AT4G12970.1,AT4G13040.7,AT4G13110.1,AT4G13395.1,AT4G13410.2,AT4G13410.1,AT4G13820.1,AT4G13860.1,AT4G14220.1,AT4G14390.2,AT4G15210.1,AT4G15210.3,AT4G15210.4,AT4G15260.1,AT4G15440.1,AT4G15630.1,AT4G15765.1,AT4G16590.1,AT4G16760.1,AT4G16760.2,AT4G17460.1,AT4G17470.1,AT4G17470.3,AT4G17470.4,AT4G17470.2,AT4G18197.1,AT4G18250.1,AT4G18253.1,AT4G18440.1,AT4G18670.1,AT4G18910.1,AT4G19660.2,AT4G19660.1,AT4G21500.1,AT4G21830.2,AT4G21830.1,AT4G22305.1,AT4G22530.2,AT4G23220.1,AT4G23470.1,AT4G23570.3,AT4G23610.1,AT4G23810.1,AT4G23870.1,AT4G23890.1,AT4G24340.1,AT4G24350.4,AT4G24350.1,AT4G24660.2,AT4G24830.1,AT4G24940.1,AT4G25070.1,AT4G25780.1,AT4G25960.1,AT4G26070.1,AT4G26520.4,AT4G26530.1,AT4G26940.1,AT4G27240.2,AT4G27410.2,AT4G27860.1,AT4G28230.1,AT4G28300.1,AT4G28480.1,AT4G28780.1,AT4G29700.1,AT4G30230.1,AT4G30450.1,AT4G30460.1,AT4G30530.1,AT4G30720.1,AT4G32870.1,AT4G33050.3,AT4G34380.1,AT4G34710.2,AT4G35160.1,AT4G35180.2,AT4G35180.1,AT4G35310.2,AT4G36110.1,AT4G36950.1,AT4G37410.1,AT4G37640.1,AT4G38770.1,AT4G39030.1,AT5G01610.1,AT5G01840.1,AT5G01850.2,AT5G01850.1,AT5G01900.1,AT5G01960.1,AT5G02760.1,AT5G02940.1,AT5G03150.1,AT5G03204.1,AT5G03350.1,AT5G03995.1,AT5G05590.1,AT5G05600.1,AT5G05600.2,AT5G05890.1,AT5G06860.1,AT5G06870.1,AT5G07010.1,AT5G08790.1,AT5G10300.1,AT5G10480.1,AT5G10930.1,AT5G12950.1,AT5G13220.1,AT5G13220.7,AT5G16030.2,AT5G16170.1,AT5G17000.2,AT5G17060.1,AT5G17490.1,AT5G18020.1,AT5G18030.1,AT5G18080.1,AT5G19090.3,AT5G19100.1,AT5G19110.1,AT5G19190.1,AT5G19240.1,AT5G19980.1,AT5G20900.1,AT5G21960.1,AT5G22060.1,AT5G22545.1,AT5G22560.1,AT5G22570.1,AT5G22630.1,AT5G23820.1,AT5G24210.1,AT5G24530.1,AT5G24770.1,AT5G24770.2,AT5G24780.2,AT5G24780.1,AT5G25010.1,AT5G26260.1,AT5G26700.1,AT5G26690.1,AT5G27520.1,AT5G28237.1,AT5G35790.1,AT5G36220.1,AT5G37480.1,AT5G38710.1,AT5G40210.1,AT5G40610.1,AT5G41120.3,AT5G41120.1,AT5G42650.1,AT5G42655.2,AT5G42860.1,AT5G43745.1,AT5G44568.1,AT5G44570.3,AT5G44680.1,AT5G44720.1,AT5G44820.1,AT5G45000.1,AT5G45040.1,AT5G45110.1,AT5G45110.2,AT5G45180.1,AT5G45500.3,AT5G45510.2,AT5G46230.1,AT5G46420.1,AT5G48545.2,AT5G49170.1,AT5G50200.1,AT5G51560.1,AT5G51750.1,AT5G52100.1,AT5G52120.1,AT5G52320.1,AT5G52810.1,AT5G52870.1,AT5G53900.2,AT5G54610.1,AT5G54700.2,AT5G54770.1,AT5G54860.1,AT5G55120.1,AT5G56760.1,AT5G57760.1,AT5G57780.1,AT5G58350.1,AT5G58900.1,AT5G59730.1,AT5G60300.2,AT5G60890.1,AT5G61010.2,AT5G61210.1,AT5G62610.1,AT5G62770.1,AT5G63490.1,AT5G63790.1,AT5G63790.2,AT5G64330.1,AT5G64810.1,AT5G65410.1,AT5G66280.1,AT5G66650.1,AT5G66910.1,AT5G67070.1,AT5G67150.1,AT5G67210.1,AT5G67300.1,AT5G67450.1,AT5G67540.1=<django.db.models.fields.CharField> SyntaxError: invalid syntax i need help to call models -
Python37 and Django 2 TextField not a string?
We decided to migrate our django 1.10.5 project with python 2.7.15 to a newer version of python and django. Now we are using python 3.7 and django 2. After some problems with our email sending script I found something strange. When sending automated mails we took text from a TextField in the database and inserted it into our Mail. content = content.replace('##ENTRY##', entry.text) The text field of entry is a django models.TextField. Now with python 37 it doesn't allow me to use it like that. I have to wrap the entry.text into a str() cast. But shouldn't the TextField be a string? content = content.replace('##ENTRY##', str(entry.text)) With that it works, but it lets my tummy hurt when doing it like that, since i don't understand why. -
Need 4 values to unpack in for loop; got 2 error
I am working with Django 2.0.7 and Python 3.6.3. I'm currently having an issue with iterating through a dictionary passed from views.py to my template. I'm trying to access my dict data in my HTML template. Here's my conn_db file that I use to get my data into a dict. I suspect that my error is in this function. def conn_db(groupNum): engine = create_engine('information to login to mysql') conn = engine.connect() result = conn.execute("SELECT firstName, lastName, email FROM team WHERE teamNumber LIKE \'%s\' ORDER BY LastName ASC" % groupNum) teamInfo = {} for results in result: SMSInfo.update(results) return teamInfo Here's what I have in Views.py. As you can see, I call the conn_db function here to store the dict variable in team_info. def teamroster(request): groupNum = 2 roster = conn_db(teamNum) team_info = dict(roster) return render(request, 'teamroster/teamroster.html', {'team_information':player_info}) After passing my dict into the render function, I am trying to iterate through the dict by using a for loop. Here's my template HTML code: <tbody> {% for email,FirstName,LastName,team in sms_information.items %} <tr> <td>{{ FirstName }}</td> <td>{{ LastName }}</td> <td>{{ team }}</td> <td>{{ email }}</td> </tr> {% endfor %} </tbody> I've been trying to wrap my mind around how to approach this … -
Django Rest Framework: User Registration with Default Model
I'm using DRF and want to take advantage of django's default User Model. I want to implement user registration and login with default model. how is that possible? should I add any code in views.py? Please suggest -
Django: Should I save Stripe responses as JSON in my models?
I am currently setting up a Stripe (Standard Connect) account. I know have a general best-practice question. One example: Creating a 'charge', Stripe is giving me back a JSON answer looking like that: <Charge charge id=ch_1CizRmABvPzR13WAhFXBkrYf at 0x00000a> JSON: { "id": "XXX", "object": "charge", "amount": 900, "amount_refunded": 0, "application": "ASDF", "application_fee": null, "balance_transaction": "XXX", "captured": true, "created": 1530428050, "currency": "eur", "customer": null, "description": null, "destination": null, "dispute": null, "failure_code": null, "failure_message": null, "fraud_details": { }, "invoice": null, "livemode": false, "metadata": { }, "on_behalf_of": null, "order": null, "outcome": { "network_status": "approved_by_network", "reason": null, "risk_level": "normal", "seller_message": "Payment complete.", "type": "authorized" }, "paid": true, "receipt_email": null, "receipt_number": null, "refunded": false, "refunds": { "object": "list", "data": [ ], "has_more": false, "total_count": 0, "url": "/v1/charges/ch_1CizRmABvPzR13WAhFXBkrYf/refunds" }, "review": null, "shipping": null, "source": { "id": "XXX", "object": "card", "address_city": null, "address_country": null, "address_line1": null, "address_line1_check": null, "address_line2": null, "address_state": null, "address_zip": "42424", "address_zip_check": "pass", "brand": "Visa", "country": "US", "customer": null, "cvc_check": "pass", "dynamic_last4": null, "exp_month": 4, "exp_year": 2024, "fingerprint": "whM4LE8uZm9vdxIa", "funding": "credit", "last4": "4242", "metadata": { }, "name": null, "tokenization_method": null }, "source_transfer": null, "statement_descriptor": null, "status": "succeeded", "transfer_group": null } As I am now deciding about the database model and the fields, the question I …