Skip to content

Tag: django

Sorting out Django and MySQL in virtualenv

I’m following this tutorial to get started with Django, but I’m very confused about how to integrate MySQL. Doing this in the context of virtualenv (which is new to me) seems to complicate things even further. I’m running on Ubuntu and the MySQL server is on another host. Here are my specifi…

How to check if the object has property in view in Django?

I am trying to get the documents property in a general function, but a few models may not have the documents attribute. Is there any way to first check if a model has the documents property, and then conditionally run code? Answer You can use hasattr() to check to see if model has the documents property. Howe…

How to add column in ManyToMany Table (Django)

From the example of Django Book, I understand if I create models as following: The Django would create a new table(A_B) beyond Table A, which has three columns: id a_id b_id But now I want to add a new column in the Table A_B, thus would be very easy if I use normal SQL, but now anyone can help me

Determine if Django is running under the development server

Is there a way to determine if Django is running on localhost and setting the DEBUG variable in settings.py accordingly. So that if I run the server locally it will set DEBUG to True and otherwise set it to False. Localhost: python manage.py runserver Not localhost: python manage.py runserver 0.0.0.0:8000 Ans…

Django:any way to remove this clear field?

Is there any way I can remove this model form file field’s ‘clear’ checkbox?.I know that I can define the ‘custom’ widget for file field but how to address this checkbox in that? Answer You need to change the widget from the ClearableFileInput to Fileinput https://docs.djangoproj…

Nothing happens when I do: python manage.py command

I’m new to django and currently going through the main tutorial. Even though it was working earlier, when I do python manage.py runserver OR python manage.py -h OR with any other command, the shell doesn’t output anything. Wondering what I’m doing wrong. Answer First, check if python is full…