Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Hr Lines Always Missing Every 3rd Rows
Hope that someone can help. hr lines always missing every 3rd rows. Thanks in advance. Mr Toh {% for board in boards %} <p>{{ board.name }}</p> <hr> {% endfor %} </tbody> -
ImportError using python if __name__ == "__main__"
I currently inherited a codebase that looks something like this. project manage.py |_ config |_ settings |_ wsgi.py |_ project |_ app1 |_ app2 |.... <-- many more Django apps |_ a_new_app |_ __init__.py |_ run.py |_ foo.py |_ bar.py I added a new app with some .py files which imports from other apps too in the same package and other app packages too in the project. All is well till I tried to run python project/a_new_app/run.py Then I started getting import error here is how my run.py looks. # run.py from project.a_new_app.foo import Foo class App(): def method(self, key): data = {"some-key": Foo} return data.get(key) .... more methods here if __name__ == "__main__": app = App() app.loop_forever() I got this error File "project/a_new_app/run.py", line 7, in <module> from project.a_new_app.foo import Foo ImportError: No module named project.a_new_app.foo My working directory is /user/me/PycharmProjects/project, Thanks. -
django-haystack search not have reuslt
This is very confusing, I don't know why the fuzzy query seems to be invalid for any reason.there is nothing to find, why? there is nothing to show -
Java REST api vs Django REST api for ML
It's been trivial thing for me!, and bugging me for over a 2 weeks. My Project Contains MVC in Java - Spring+Hibernate. I've been using Java for more than 4 years, so far it's good, but recent Machine learning bothering me so much because i just want to restart my 4 year old project in Machine Learning(It's best thing for my project, And i can't reinvent algorithm to match for my project). I read lot about Machine learning, I was so keen at Google TensorFlow, Sadly i can't use it in Java as i know, The API by google is not ready for Java.On the other hand i read about DL4J, it's seems okay but i have to explore it. On the Python side TensorFlow works flawless and SciKit too, but i'm new to Python Django REST framework. I'll quickly may catch up DRF. And it's seems that DRF is so light weight and pretty great without like spring annotation and hibernate annotation and too many stupid things. But one thing bothering so much is that will i stick to Java with DL4J or switch it to Python DRF? Please suggest me which track should i choose? Thanks -
Update Django POST Request
If my POST request doesn't have a Required field, (say password), I need to set a temporary password to the field. Since it is set as Required field, we need to update the POST request somehow. How can I implement it? Also recommend if there's any alternative method Thank in advance, -
How can I use default custom user model instead of Django auth user model?
I've been working on my Django project that was created from django-admin startproject myproject. However, as I wanna migrate my Django project to django-cookiecutter. I'm trying to move codes manually, and I'm stuck with some migration issue between custom user model and Django default user model. I'm having the following issue. django.db.migrations.exceptions.InconsistentMigrationHistory: Migration account.0001_initial is applied before its dependency users.0001_initial on database 'default'. Because of this, I can't migrate my custom user model. Is there a way that I can use custom user model keeping the existing user data? -
Are There Any Python Software Developers in Johannesburg Offering Mentorship?
Good day all I am currently teaching myself Python using materials that I can find online. I would like to know if there is anybody in the Johannesburg (Gauteng, SA) area who is available to offer mentoring and coaching in Python, PyQt, PyCharm, Anaconda, Django fields of expertise? Kind Regards Ntlatseng Magakwa -
How to get mac address or Ip address and any other unique id,? we want to get client(customer) any unique id? thanks in advance
My question is as simple as it seems. I want to find the IP address and the MAC address. I tried many solutions I need to get mac address of the client machine. Is this possible to get mac address of the client machine? If not, is this possible to get any other unique id from client machine? -
Django Contact Form with Bootstrap
I have app called contact that renders extends of home.html with footer/header. I put bootstrap form in there with below code: <div class="form-area"> <form role="form"> <div class="form-group"> <input type="text" class="form-control" id="name" name="name" placeholder="Name" maxlength="70" required> </div> <div class="form-group"> <input type="text" class="form-control" id="email" name="email" placeholder="Email" required> </div> <div class="form-group"> <input type="text" class="form-control" id="subject" name="subject" placeholder="Subject" maxlength="70" required> </div> <div class="form-group"> <textarea class="form-control" type="textarea" id="message" placeholder="Message" maxlength="300" rows="7"></textarea> </div> <button type="button" id="submit" name="submit" class="btn btn-m btn-secondary">Submit Form</button> </form> I want to send emails using that form, I already know that I should use cripsy forms but I have no idea where to start. I am not sure if I should create model or form in django. There are some tutorials that show email logic and templates but they are using built-in forms. Many thanks. -
Django Unit test cases
Whats the best way to write django unit test cases that include database changes like changing status of an entity??? For Eg:- I have different test cases where status of an entity changes on the basis of different action from users that causes changes on databases level. Whats the best approach to deal with test cases for such operations. -
Django: SMTPRecipientsRefused for EmailBackend, but not smtplib
I set up Django's password recovery process, using the following settings in settings.py: EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.someserver.com' # mail service smtp EMAIL_HOST_USER = 'someone@fakeserver.com' # email id EMAIL_HOST_PASSWORD = 'my password' #password EMAIL_PORT = 465 EMAIL_USE_SSL = True Elsewhere in my application, I use smtplib to send emails without any problem using the same server settings. However, when I test the password recovery process, it fails with the following error: SMTPRecipientsRefused 451 Temporary local problem - please try later I tried several server settings without any luck. -
Method Not Allowed (GET): / in django
from django.views.generic import View from django.http import HttpResponse class home(View): def post(self,request): return HttpResponse('Class based view') When I tried to define above method it says Method Not Allowed (GET): / Can anyone please help me on this issue? -
open edx SSL: CERTIFICATE_VERIFY_FAILED
I recently set up the e-commerce module, now I'm getting this error when I try to create a new course in e-commerce. Error! Failed to publish commerce data for course-v1:organization+t101+2017 to LMS. also, I'm getting this log: - Failed to publish commerce data for [course-v1:Org1+CU1+2017] to LMS. Traceback (most recent call last): File "/edx/app/ecommerce/ecommerce/ecommerce/courses/publishers.py", line 133, in publish response = requests.put(url, data=json.dumps(data), headers=headers, timeout=self.timeout) File "/edx/app/ecommerce/venvs/ecommerce/local/lib/python2.7/site-packages/requests/api.py", line 120, in put return request('put', url, data=data, **kwargs) File "/edx/app/ecommerce/venvs/ecommerce/local/lib/python2.7/site-packages/requests/api.py", line 53, in request return session.request(method=method, url=url, **kwargs) File "/edx/app/ecommerce/venvs/ecommerce/local/lib/python2.7/site-packages/requests/sessions.py", line 468, in request resp = self.send(prep, **send_kwargs) File "/edx/app/ecommerce/venvs/ecommerce/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send r = adapter.send(request, **kwargs) File "/edx/app/ecommerce/venvs/ecommerce/local/lib/python2.7/site-packages/requests/adapters.py", line 447, in send raise SSLError(e, request=request) SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) 2018-11-14 13:56:34,049 ERROR 90986 [ecommerce.extensions.api.serializers] /edx/app/ecommerce/ecommerce/ecommerce/extensions/api/serializers.py:418 - Failed to save and publish [course-v1:Org1+CU1+2017]: [Failed to publish commerce data for course-v1:Org1+CU1+20177 to LMS.] It's showing SSL certificate verification failed Can anyone tell did i missed any configuration settings? Thanks -
deploy Django2 on heroku , but can not open the page
I use django2.1.3 on python3, here is my settings.py: import os import django_heroku # Build paths inside the project like this:os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) --snip- # Activate Django-Heroku. django_heroku.settings(locals()) #setting Heroku cwd = os.getcwd() if cwd == '/app' or cwd[:4] == '/tmp': import dj_database_url DATABASES= { 'default': dj_database_url.config(default='postgres://localhost') } SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO','https') #ALLOWED_HOSTS = ['*'] BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR,'static'), ) but after I push the project to heroku ,I can not open the webpage, then I run the command heroku logs, here is the log : 2018-11-16T03:47:55.000000+00:00 app[api]: Build succeeded 2018-11-16T03:48:48.803513+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=desolate-oasis-71960.herokuapp.com request_id=703f8297-76f6-4434-9fcc-805c059fd3d8 fwd="202.119.45.10" dyno= connect= service= status=503 bytes= protocol=https -
Django Allauth Google Integration hangs and timesout on /accounts/google/login/callback
I am having some issues with my new Zappa Django app. What is weird is that I had this same code implemented on a different instance, and it worked fine. Now that I have just redeployed, I am getting an issue with my Google Oauth integration using Django-Allauth. I can access my login page fine, which redirects me to /accounts/google/login from which I can select my Google account. When I do that, it then hangs until the request is timed out. Here is the request log: [1542344053895] [INFO] 2018-11-16T04:54:13.895Z a9ff335f-e95b-11e8-b081-5b1d3f780ffe 136.24.233.181 - - [16/Nov/2018:04:54:13 +0000] "GET /login/ HTTP/1.1" 200 1928 "https://example.com/accounts/google/login/callback/?state=QkKCasdSut7aQasdO&code=4/lwBmAlt9asjdjasdYsgZirWPDkGTasd9asd9uw7OzFqMFjrlo7nzjA_knnE_Wuz_xQ-p4HtAZZOjdbJQyoToI&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36" 0/41.995 I've never had this issue, so I feel like it may be something with the social account setup, but it seems to mimic my previous configuration. There are no errors in the logs, so I can't quite figure this out -
How to pass value from html to django view?
I have an option list in html. <select> <option value="Please select" disabled selected>- Please Select -</option> <option value="Iphone">Iphone</option> <option value="Samsung">Samsung</option> </select> When the user select one of the option, the particular table with data will appear. In views.py: dev_model = Device.objects.filter(name='name').all() I want to get the data from html, then filter the option with my database in field 'name',if is same, the data will be retrieved and display in html. -
Access django celery results in views
I'm using the django-celery-results extension and successfully saving records in the db backend table, celery_results_taskresults. My tasks are associated with model instances, and I want to be able to list them as attributes of each instance, in views and ultimately templates. I can see them in the admin interface, but can't figure out how to access them in a list. I though of creating an @property on the model in question, using raw sql, but the sql examples I've seen all refer to a model, and if there's a celery_results_taskresults model, I can't find it. -
Django vs Flask?
I'm working on a university project and trying to decide which framework would be better for us (group project). Here is the info about the project and the members that are of note: Group project (3 of us) due in 2 weeks Need to design a user interface for our database server (website backed by DB) MySQL was used for database design We all have fairly decent python experience (and I'd like to think we are all capable people, willing and able to learn - even in this short amount of time) We have little to no web development experience I know there are plenty of differences from what online (although both would work). I may be wrong, but I think the most important factor for us would be which framework allows us to work and connect to MySQL most easily. Thank you so much to people who answer, it will be super appreciated! -
Django compress error: Invalid input of type: 'CacheKey'
We suddenly started getting this issue when compressing django static files on production servers. Ubuntu 16.04, Python 3.x, Django 1.11. I am using an ansible-playbook to deploy. The error is as follows: Invalid input of type: 'CacheKey'. Convert to a byte, string or number first. It doesn't seem to be an issue in one of the static files but a general issue. Every time we run it, we get a different file. I was looking for any clues on google and nothing shows up with the same error. -
Django ERROR "Intersection is not supported on this database backend"
I just convert database backend from sqlite to mysql. But When I test my feature in project is ERROR. NotSupportedError at /filter/ intersection is not supported on this database backend. In my view.py have Django ORM Union, Intersection. I think this is the troublemakers. Why It can't use Union, Intersection in MySql Backend. I try to fix it. But I don't know how. Please Help me T^T -
get all fields in UpdateView django
Is it possible to get all the fields from a given model without writing list of all the fields in the view.py file when working with UpdateView in class-based views? -
why can't push the lasted created app to heroku?
I am practicing django2 on Python3, and want to deploy the project on heroku. when I run the fellow command: $ git init $ git add . $ git commit -am "Ready for deployment to heroku" $ git staus everything is fine ,then: $ heroku create and the last command I get some problem: $ git push heroku master app pacific-plateau-99737. was deleted already, how to push the new created app hidden-escarpment-89466? -
How to make an atomic transaction if my transaction is based on multiple response with same time
I am requesting json response from new Zealand api for a django webproject but they are passing 5 response of same request with same no difference in time and my transaction is commited but frontend user is send 5 mails at the same time -
Dango: Internet Explorer POSTs an empty form
I have a ModelForm that works perfectly for FireFox and Chrome, but for some reason, whenever anybody submits the form with IE, the server just receives the form with empty values. I've verified this by printing the submitted values in form.is_valid() (as you can see below). Here is my code: template.html: <form id="tracking_form" action="/tracking/{{ view.person.id }}" method="POST"> {% csrf_token %} {{ form.person }} <input type="submit" class="btn btn-default" value="Add Data" style="width: 190px;"> </form> forms.py: class TrackingForm(forms.ModelForm): def __init__(self, active_student=None, *args, **kwargs): super(TrackingForm, self ).__init__(*args, **kwargs) points_dict = {'class': 'weekday_points', 'min': 0, 'max': 100 } arrived_dict = { 'class': 'not_required' } for field in self.fields.values(): field.widget.attrs['form'] = 'tracking_form' field.widget.attrs['class'] = 'form_field' field.required = False self.fields['monday_points'].widget.attrs.update(points_dict) self.fields['tuesday_points'].widget.attrs.update(points_dict) self.fields['wednesday_points'].widget.attrs.update(points_dict) self.fields['thursday_points'].widget.attrs.update(points_dict) self.fields['friday_points'].widget.attrs.update(points_dict) self.fields['monday_arrived'].widget.attrs.update(arrived_dict) self.fields['tuesday_arrived'].widget.attrs.update(arrived_dict) self.fields['wednesday_arrived'].widget.attrs.update(arrived_dict) self.fields['thursday_arrived'].widget.attrs.update(arrived_dict) self.fields['friday_arrived'].widget.attrs.update(arrived_dict) def is_valid(self): # This is just here to print the values server receives for name, field in self.fields.items(): if field.disabled: value = self.get_initial_for_field(field, name) else: value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name)) print(name, ":", field.clean(value)) valid = super(TrackingForm, self).is_valid() return valid class Meta: model = models.Tracking exclude = ('person',) This is the log when submitting the form with FireFox: 2018-11-16 02:23:15 week : 3 2018-11-16 02:23:15 term : 4 2018-11-16 02:23:15 year : 2018 2018-11-16 02:23:15 b1 : fasd 2018-11-16 … -
Can one ManyToMany Field contain 2 Tables? -- Django
Can one ManyToMany Field contain 2 Tables? I would like to achieve like this name_b = ManyToManyField("A, B", related_name="+", blank=True) class A(models.Model): name = models.CharField(max_length=50, blank=True, default="") add_time = models.DateTimeField(auto_now=True) class B(models.Model): name = models.CharField(max_length=50) add_time = models.DBateTimeField(auto_now=True) class C(models.Model): name = models.CharField(max_length=50) name_b = ManyToManyField(???"A, B"???, related_name="+", blank=True) add_time = models.DateTimeField(auto_now=True) Can it be possible? Thank you so much for any advice.