Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Reverse for 'post-detail' with arguments '(38,)' not found
Full error: Reverse for 'post-detail' with arguments '(38,)' not found. 1 pattern(s) tried: ['(?P[^/]+)/posts/(?P[0-9]+)/$'] models.py class Post(models.Model): article_title = models.CharField(max_length=100) content = models.TextField() date_published = models.DateTimeField(db_index=True, default=timezone.now) game = models.ForeignKey('library.Game', on_delete=models.CASCADE) article_image = models.ImageField(default='/media/default.png', upload_to='article_pics') platform = models.CharField(default='PC', max_length=20) def __str__(self): return self.article_title class Meta: ordering = ["-date_published"] def get_absolute_url(self): return reverse('post-detail', kwargs={'pk': self.pk}) class Game(models.Model): title = models.CharField(max_length=100) description = models.TextField() date_posted = models.DateTimeField(default=timezone.now) cover = models.ImageField() cover_display = models.ImageField(default='default.png') developer = models.CharField(max_length=100) twitter = models.CharField(max_length=50, default='') def __str__(self): return self.title views.py class TitlePostListView(ListView): model = Post template_name = 'main/title_posts.html' context_object_name = 'posts' paginate_by = 5 def get_queryset(self): title = get_object_or_404(Game, title=self.kwargs.get('title')) return Post.objects.filter(game=title).order_by('-date_published') def get_context_data(self, **kwargs): context = super(TitlePostListView, self).get_context_data(**kwargs) context['game'] = get_object_or_404(Game, title=self.kwargs.get('title')) return context class PostDetailView(DetailView): model = Post urls.py path('<str:title>/posts', TitlePostListView.as_view(), name='title-posts'), path('<str:title>/posts/<int:pk>/', PostDetailView.as_view(), name='post-detail'), I'm trying to make the path something like domain.com/Minecraft/posts/38 but I get an error probably because str:title is not defined. I'm not exactly sure how to go about adding it to my PostDetailView. -
Cannot decode POST request body in the backend
I send JSON data in the POST request body to Python backend (Django). In the backend I receive this content: body_unicode = request.body.decode('utf-8') print(body_unicode) {"holdingTime":0,"asma40":49,"asma60":18,"temperature":9,"visibility":9999,"windIntensity":1.5,"windDirection":"VRB","airportDepDelay":8,"csvData":"NUM,AIRLINE_ARR_ICAO,WAKE,SIBT,SOBT,PLANNED_TURNAROUND,DISTANCE_FROM_ORIGIN,DISTANCE_TO_TARGET\n1,AEA,H,2016-01-01 04:05:00,2016-01-01 14:10:00,605,9920.67,5776.89\n2,AEA,H,2016-01-01 04:25:00,2016-01-01 06:30:00,125.0,10060.80,483.93\n3,AVA,H,2016-01-01 05:05:00,2016-01-01 07:05:00,120.0,8033.86,8033.86\n4,IBE,H,2016-01-01 05:20:00,2016-01-01 10:40:00,320.0,6000.00,8507.73\n5,IBE,H,2016-01-01 05:25:00,2016-01-01 10:50:00,325.0,6698.42,6698.42\n6,IBE,H,2016-01-01 05:30:00,2016-01-01 08:10:00,160.0,10699.06,1246.30\n7,IBE,H,2016-01-01 05:30:00,2016-01-01 11:00:00,330.0,9081.35,8033.86\n8,IBE,H,2016-01-01 05:40:00,2016-01-01 11:35:00,355.0,5776.89,8749.87\n9,ANE,M,2016-01-01 05:50:00,2016-01-01 14:50:00,540.0,284.73,284.73\n10,ETD,H,2016-01-01 06:35:00,2016-01-01 08:00:00,85.0,5647.10,5647.10\n11,IBS,M,2016-01-01 06:50:00,2016-01-01 08:00:00,70.0,547.36,1460.92\n12,IBE,H,2016-01-01 06:50:00,2016-01-01 10:35:00,225.0,6763.16,6763.16\n13,IBE,H,2016-01-01 06:50:00,2016-01-01 10:50:00,240.0,7120.40,7120.40\n14,IBE,H,2016-01-01 06:50:00,2016-01-01 10:55:00,245.0,7010.08,6000.00\n15,QTR,H,2016-01-01 06:55:00,2016-01-01 08:30:00,95.0,5338.52,5338.52\n16,IBS,M,2016-01-01 07:00:00,2016-01-01 07:45:00,45.0,485.52,1721.09\n17,IBS,M,2016-01-01 07:00:00,2016-01-01 07:45:00,45.0,394.98,429.37\n18,ELY,M,2016-01-01 07:05:00,2016-01-01 08:30:00,85.0,3550.48,3550.48\n19,AAL,H,2016-01-01 07:05:00,2016-01-01 12:05:00,300.0,5925.61,5925.61\n20,TVF,M,2016-01-01 07:30:00,2016-01-01 08:10:00,40.0,1030.31,1030.31\n"} But if I do this, I get error: body_unicode = request.body.decode('utf-8') body = json.loads(io.StringIO(body_unicode)) print(body) Error: Internal Server Error: /batch_predict Traceback (most recent call last): File "/Users/tuter/anaconda3/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/Users/tuter/anaconda3/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/tuter/anaconda3/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/tuter/anaconda3/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, **kwargs) File "/Users/tuter/Desktop/test/backend/views.py", line 192, in batch_predict_endpoint body = json.loads(body_unicode) File "/Users/tuter/anaconda3/lib/python3.6/json/init.py", line 354, in loads return _default_decoder.decode(s) File "/Users/tuter/anaconda3/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Users/tuter/anaconda3/lib/python3.6/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) -
How to drag-and-drop (order) and hide columns in Django admin
I have a model and it is presented as a list in the admin panel. Im looking for the way how to allow the user to order columns by drag-and-drop, like excel or any common table viewer. Another question is how to add functionality that the user can hide/show certain columns. I know how to do in statically. Also, I found plugins on how to reorder rows in the table. But could not find any implementation for working with columns. -
Getting Django, VUE, CORS and CSRF working with a real world example
I'm really stuck. Here's what I'm trying to do. KEEP CSRF On. - please don't tell me to turn it off. I have an API app run by Django and Django Rest Framework I have a frontend app run by Vue I have installed django-cors-headers to manage CORS Everything works great localy. As soon as I move it to production, I start getting CSRF errors. Here's how everything works. I've seen answers all over that have said everything from turning off CSRF to allowing all for all the things. I want to do this right and not just shut things off and open everything up and end up with a security hole. So, here's what I have. Installed: django-cors-headers django-rest-framework drf-nested-routers ... and others I have the api running at api.websitename.com and the Vue.js app is running at websitename.com. GET requests work great. OPTION requests seem to work. Any risky request does not work. For my CORS I have 'corsheaders.middleware.CorsMiddleware', installed before my other MIDDLEWARE. Then my CORS settings are: CORS_ALLOW_CREDENTIALS = True CORS_ORIGIN_WHITELIST = ( '*.websitename.com', ) And my CSRF settings are: CSRF_TRUSTED_ORIGINS = [ "api.websitename.com", ] No matter how I play with these, I end up with a … -
Django: My function is returning an object instead of the return value
Models.py class Document(models.Model): def test(): # return "hello" Views.py print(Document.test) When I run this code, it prints this: <function Document.file_name at 0x03DF9030>. How do I get it to print "hello"? Thank you. -
UNIQUE constraint failed in django project
I have an application in django 1.11, where I have an app 'accounts' to manage users. User can have assigned roles, with which there are problems when creating usera using manager. When adding a username, I get an error: IntegrityError at /accounts/add_user/ UNIQUE constraint failed: accounts_role.id Here is my model: class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField(_('Email address'), unique=True) first_name = models.CharField(_('First name'), max_length=60, blank=True) last_name = models.CharField(_('Last name'), max_length=60, blank=True) roles = models.ManyToManyField(Role, unique=False) USERNAME_FIELD = 'email' REQUIRED_FIELDS = [] objects = UserManager() class Meta: verbose_name = _('user') verbose_name_plural = _('users') Below is Role class: class Role(models.Model): ADMIN = 1 PLAYER = 2 ROLE_CHOICES = ( (ADMIN, 'admin'), (PLAYER, 'player'), ) id = models.PositiveSmallIntegerField(choices=ROLE_CHOICES, default=2, primary_key=True, unique=False) def __str__(self): return self.get_id_display() Here is manager: class UserManager(BaseUserManager): def create_user(self, email, password): user = self.model(email=email, password=password) user.set_password(password) user.is_staff = False user.is_superuser = False user.save(using=self._db) role = Role.objects.create(id=2) user.roles.add(role) return user -
Django Tags save related objects
Good day all! I'm trying to make a save form with some kind of fields, where each field has its own tag and only one. But when I save the form, I have one field that saves not one tag but two at once. Although this should not be. Help me solve the issue please. /models.py class Post(models.Model): # Books user = models.ForeignKey(User, on_delete=models.CASCADE) image = VersatileImageField( 'Image', upload_to='media_my/',null=True, blank=True ) title = models.CharField(max_length=150, db_index=True) slug = models.SlugField(max_length=150, unique=True, blank=True) tags = models.ManyToManyField('Tag', blank=True, related_name='posts') b1 = models.ManyToManyField('B1', blank=False, related_name='bo1') b2 = models.ManyToManyField('B2', blank=False, related_name='bo2') b3 = models.ManyToManyField('B3', blank=False, related_name='bo3') b4 = models.ManyToManyField('B4', blank=False, related_name='bo4') date_pub= models.DateTimeField(auto_now_add=True) def get_absolute_url(self): return reverse('post_detail_url', kwargs={'slug':self.slug}) def save(self, *args, **kwargs): if not self.id: self.slug= gen_slug(self.title) super().save(*args, **kwargs) def __str__(self): return self.title class Meta: ordering = ['-date_pub'] class Tag(models.Model): # Tags of books title=models.CharField(max_length=50) slug=models.SlugField(max_length=50, unique=True) def get_absolute_url(self): return reverse('tag_detail_url', kwargs={'slug': self.slug}) def __str__(self): return self.title class B1(models.Model): b1 = models.CharField(max_length=286) tags = models.ManyToManyField('Tag', blank=True, related_name='t1') date_save= models.DateTimeField(auto_now_add=True) def __str__(self): return self.b1 class B2(models.Model): b2 = models.CharField(max_length=286) tags = models.ManyToManyField('Tag', blank=True, related_name='t2') date_save= models.DateTimeField(auto_now_add=True) def __str__(self): return self.b2 class B3(models.Model): b3 = models.CharField(max_length=286) tags = models.ManyToManyField('Tag', blank=True, related_name='t3') date_save= models.DateTimeField(auto_now_add=True) def __str__(self): return self.b3 class … -
Django model for a legacy table containing a custom data type
I am working with a Postgresql legacy table and found that some fields have custom data types. For example, instead of e.g. character varying, the column color has color_type as data type, with permissible options [red|green|blue|black]. Relying on the inspectdb command, the automatically generated model contains the following line and comment: color = models.TextField(blank=True, null=True) # This field type is a guess. I would "clean" this line as described in the following class, but am not sure a) if it will properly "fit" the existing table (e.g. if I write new objects inside the table), and b) whether if migrated to a new database, the custom_type would be correctly reproduced: class Things(models.Model): name = models.CharField(max_length=30, null=True, blank=True) RED = 'red' GREEN = 'green' BLUE = 'blue' BLACK= 'black' COLOR_CHOICES = ( (RED, 'red'), (GREEN, 'green'), (BLUE, 'blue'), (BLACK, 'black'), ) color = models.CharField( max_length = 10, choices = COLOR_CHOICES, default = RED, null = True, blank = True ) def __str__(self): return self.name class Meta: managed = False db_table = 'myuser' What is the proper way to reflect this custom data type in the Django model? -
How do I use a SoupStrainer for attributes that contain dashes?
I'm using Django and Python 3.7. I want to use BeautifulSoup and a SoupStrainer to look for specific elements witih attributes in my document. But how do I do that if the attribute contains a dash? I would like to do this my_strainer = SoupStrainer('a', data-id="aaa") but this results in the error Can't assign to function call complaining about the "data-id" attribute. If I change "data-id" to just "id" then everything runs, but then I don't get the results I want. -
Django: How to send csrf_token with Ajax
I have my Ajax in a jQuery function: btnApplyConfig.js: $(".btnApplyConfig").click(function(){ var token = $("input[name=csrfmiddlewaretoken]").val(); // Some other vars I'm sending properly console.log('token: '+token); //printing correctly $("#"+frm).submit(function(e){ e.preventDefault(); console.log('Post method via ajax'); $.ajax({ url: '/ajax/validate_config', type: 'POST', data: { 'token': token, //and other stuff I'm sending properly }, dataType: 'json', }); } } my Django view: def validate_config(request): token = request.GET.get('token', None) #some other vars I've sent ok with ajax data = { #some vars 'token': token, } if request.method == 'POST': item = MyClass.objects.filter(my_keyword=my_filter_values).update(my_ajax_values) return JsonResponse(data) All the data is being processed properly, the only problem for me is that I'm getting the following error: Forbidden (CSRF token missing or incorrect.): /ajax/validate_config/ I've put some prints in view in order to check if vars are being sent properly, and yes they are. How could I handle it? I checked some tutorials but I couldn't find a solution so far. -
AttributeError: 'modify_settings' object has no attribute 'wrapped' - Django LiveServerTestCase
I am getting the following error when doing a simple test. Error AttributeError: 'modify_settings' object has no attribute 'wrapped' This is my test: class FunctionalTest(LiveServerTestCase): def setUp(self): self.browser = webdriver.Firefox() def tearDown(self): self.browser.quit() def test_sample_test(self): print(f'{self.live_server_url}/login/') self.browser.get(f'{self.live_server_url}/login/') self.assertTrue(True) I am not quite sure why this is happening, but I can see the following is happening: test_sample_test seems to succeed, the browser opens and goes to the page and then closes. LiveServerTestCase.tearDownClass seems to get called twice. If I comment out the call to _live_server_modified_settings.disable() within django.tests.testcases.LiveServerTestCase.tearDownClass then the test "passes" The pytest test runner shows 6 tests found, my first 5 unit test pass fine, then test in this file shows one 'green dot' to say test passed and then and 'E' for error. So in total it looks like there is somehow 7 tests. I am using whitenoise for static file management, so I have tried to remove that in case it was interacting, but it did not change anything. I ran through the TDD book from Django last week and did not encounter this issue (on another environment though) Stack trace from error log: tp = <class 'AttributeError'>, value = None, tb = None def reraise(tp, value, tb=None): … -
Django, tinymce, GCS and CORS
Django app is running on AppEngine Standard environment with static files served from the GCS bucket. Static files worked fine without CORS settings. The problem is only with TinyMCE fonts. I'm getting errors: Access to font at 'https://storage.googleapis.com/MY-BUCKET/static/tinymce/js/tinymce/skins/lightgray/fonts/tinymce.woff' from origin 'https://MY-APP.appspot.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. GET https://storage.googleapis.com/MY-BUCKET/static/tinymce/js/tinymce/skins/lightgray/fonts/tinymce.woff net::ERR_FAILED Access to font at 'https://storage.googleapis.com/MY-BUCKET/static/tinymce/js/tinymce/skins/lightgray/fonts/tinymce.ttf' from origin 'https://MY-APP.appspot.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. GET https://storage.googleapis.com/MY-BUCKET/static/tinymce/js/tinymce/skins/lightgray/fonts/tinymce.ttf net::ERR_FAILED I tried to set CORS but it doesn't work for those fonts: [ { "origin": ["https://MY-APP.appspot.com", "http://MY-APP.appspot.com"], "responseHeader": ["Content-Type", "Access-Control-Allow-Origin", "X-Requested-With"], "method": ["GET", "PUT", "HEAD", "POST"], "maxAgeSeconds": 3600 } ] -
Would you either learn Ruby on rails or Python for web development? [on hold]
What would be better to learn for web development Python or Ruby on rails? -
Why is my CSS file not working in Django?
I've read a bunch of other people's solution to this but can't seem to get anything to work. My CSS file in Django is not connecting to my HTML. Here is my structure: This is my CSS file: .pagination { text-align: center; margin-top: 1em; } .pagination-number { padding: 0.5em 0.8em; border-radius: 2px; color: #fff; background-color: #6D85C7; } .pagination-number:hover, .pagination-current { background-color: #3354AA; } .pagination-action { margin: 0 0.1em; display: inline-block; padding: 0.5em 0.5em; color: #B9B9B9; font-size: 1.3em; } .pagination-action:hover, .pagination-previous, .pagination-next { color: #3354AA; } .ui-menu .ui-menu-item a{ font-size: 10px; color: #96f226; border-radius: 0px; border: 1px solid #454545; } I load the CSS file in my HTML file (policy_list.html) with: {% load static %} <link rel="stylesheet" href="{% static 'css/styles.min.css' %}" type="text/css" /> But this CSS file is not being loaded when I run my Django site. For reference, here is my settings.py file: STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, '/static/'), ) STATIC_ROOT = os.path.join(BASE_DIR, 'static') I can't figure out why the CSS will not work with the HTML. I've tried messing around with the urls.py file as well but to no avail. Any help appreciated. -
Do I need to reinstall django for existing virtual environment?
I've been working on a project and have came back to run it. however whenever I runserver within virtual environment it gives me error: ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?` I've already installed django when I started working on the project. -
Connect the database Neo4j to the Django project
I write django app now and i need to connect the database Neo4j to Django project. I find it difficult for me, Anyone have experience with this? -
Can we use factory_boy in a project hosts in pythonanywhere
I have a simple question about factory_boy and pythonanywhere. Does someone know whether or not we can include the factory_boy library in a project hosts in Pythonanywhere? -
Possible to use multiple strainers wiht one BeautifulSoup document?
I'm using Django and Python 3.7 . I want to speed up my HTML parsing. Currently, I'm looking for three types of elements in my document, like so req = urllib2.Request(fullurl, headers=settings.HDR) html = urllib2.urlopen(req).read() comments_soup = BeautifulSoup(html, features="html.parser") score_elts = comments_soup.findAll("div", {"class": "score"}) comments_elts = comments_soup.findAll("a", attrs={'class': 'comments'}) bad_elts = comments_soup.findAll("span", text=re.compile("low score")) I have read that SoupStrainer is one way to improve performacne -- https://www.crummy.com/software/BeautifulSoup/bs4/doc/#parsing-only-part-of-a-document . However, all the examples only talk about parsing an HTML doc with a single strainer. In my case, I have three. How can I pass three strainers into my parsing, or would that actually create worse performance that just doing it the way I'm doing it now? -
tree structure in html with dynamic content
I have data coming from the database as the below format on query execution [(‘Country-1’, ‘state1’), (‘Country-1’, ‘state2’), (‘Country-1’, ‘state3’), (‘Country-2’, ‘state1’), (‘Country-2’, ‘state2’), (‘Country-2’, ‘state3’), (‘Country-3’, ‘state1’), (‘Country-3’, ‘state2’), (‘Country-3’, ‘state3’)] I want to convert to as this resultset as below format context = { 'countries': [ { 'Countryname': 'country1’, 'state': [ { 'Statename': 'state1'}, {'Statename': 'state2'}, {'Statename': 'state3'} ] }, { 'Countryname': 'country2’, 'state': [ { 'Statename': 'state1'}, {'Statename': 'state2'}, {'Statename': 'state3'} ] }, { 'Countryname': 'country3’, 'state': [ { 'Statename': 'state1'}, {'Statename': 'state2'}, {'Statename': 'state3'} ] } ] } So that I can iterate the data in the in HTML in Django to create the tree format: <ul class = "myUL"> {% for country in data %} <li class = "caret"> {{ country.countryname }} </li> <ul class="nested"> {% for state in country.statename %} <li>{{state.statename}}</li> {% endfor %} </ul> {% endfor %} Expected output for HTML is: Country-1 State1 State2 State3 Country -2 State1 State2 State3 Country -3 State1 State2 State3 -
Get users informations from django admin page
so im trying to get the list of my users to return them in a json format for a login page in a mobile application using djangorestframework but i found difficulties getting the informations from the admin page. So here's My admin page The users are in the Utilisateurs link , and when clicking on the link i have these informations So as u can see i want to get the informations required for a login, username and password The code i'm using is : on my serializers.py : from django.contrib.auth.models import User class UsersSerializer(serializers.ModelSerializer): class Meta: model = User fields = ('Nom d\'utilisateur') on my api_views.py file : from django.contrib.auth.models import User class UsersViewSet(viewsets.ModelViewSet): queryset = User.objects.all() serializer_class = UsersSerializer and on my urls.py i have just added this line : router.register(r'users',api_views.UsersViewSet,'Users') Thanks in advance -
How to solve the a celery worker configuration with keyword argument namespace='"CELERY"error in the celery file
I have a project name called ShippingApp and I followed the steps to set up the celery worker. I am using celery 3.1.26.post2 with python3.7 and when I want to start the Celery Worker I am getting the error below: E:\ShippingApp>celery -A ShippingApp worker -l info Traceback (most recent call last): File "c:\program files\python37\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\program files\python37\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Program Files\Python37\Scripts\celery.exe\__main__.py", line 9, in <module> File "c:\program files\python37\lib\site-packages\celery\__main__.py", line 30, in main main() File "c:\program files\python37\lib\site-packages\celery\bin\celery.py", line 81, in main cmd.execute_from_commandline(argv) File "c:\program files\python37\lib\site-packages\celery\bin\celery.py", line 793, in execute_from_commandline super(CeleryCommand, self).execute_from_commandline(argv))) File "c:\program files\python37\lib\site-packages\celery\bin\base.py", line 309, in execute_from_commandline argv = self.setup_app_from_commandline(argv) File "c:\program files\python37\lib\site-packages\celery\bin\base.py", line 469, in setup_app_from_commandline self.app = self.find_app(app) File "c:\program files\python37\lib\site-packages\celery\bin\base.py", line 489, in find_app return find_app(app, symbol_by_name=self.symbol_by_name) File "c:\program files\python37\lib\site-packages\celery\app\utils.py", line 235, in find_app sym = symbol_by_name(app, imp=imp) File "c:\program files\python37\lib\site-packages\celery\bin\base.py", line 492, in symbol_by_name return symbol_by_name(name, imp=imp) File "c:\program files\python37\lib\site-packages\kombu\utils\__init__.py", line 96, in symbol_by_name module = imp(module_name, package=package, **kwargs) File "c:\program files\python37\lib\site-packages\celery\utils\imports.py", line 101, in import_from_cwd return imp(module, package=package) File "c:\program files\python37\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File … -
How to create migration that alters a column from String to Foreign Key with existing data
I've got an existing django application in production. When building the data model we accounted for two fields we thought were going to be strings. It turns out that we need them to instead be Foreign Keys to two new Models that we're adding. These models are basically ENUM tables. I've updated the model already with the new field, generated the migrations (which obviously don't work) and have kind of hit a wall. I've started to manually edit the migration file to rename the original field (to keep the data), add the new field with the old name (which is where it fails because there is no default value), run a custom method that's supposed to handle setting the new values, and then remove the old field. I don't think the approach I'm taking is going to work, and I'm trying to understand how others may handle the same situation. Here's the code I have in my migration: # Generated by Django 2.1.2 on 2019-02-21 20:43 from django.db import migrations, models import django.db.models.deletion def migrate_values(apps, schema_editor): model = apps.get_model('app', 'model') # do stuff here to set the new values class Migration(migrations.Migration): dependencies = [ ('app', '0001_initial'), ] operations = [ … -
How do I force a Python 3 Django application on AppEngine to always use https?
When using a custom domain with a Google generated security certification, how do I get http requests to redirect to the https? I tried setting the Django property SECURE_SSL_REDIRECT to True in settings, but that didn't work. I tried adding secure:always to the app.yaml but that didn't work. Edit: Yes, this question already exists, but the solution only works with Python2. -
My ubuntu shows the error :"Segmentation fault (core dumped)" while installing django in virtual environment
Screenshot of the error "Segmentation fault (core dumped)" is shown for all operations in the virtual environment -
Django: is it possible to use filter on annotated field?
For example if I want to search by first and last names of user at the same time: I tried this, but it doesn't work: qs = User.objects.all().annotate(name=F('first_name') + ' ' + F('last_name')) qs = qs.filter(name__icontains='foo bar') Is this event possible in SQL?