How can I list urlpatterns (endpoints) on Django?

If you want a list of all the urls in your project, first you need to install django-extensions You can simply install using command. pip install django-extensions For more information related to package goto django-extensions After that, add django_extensions in INSTALLED_APPS in your settings.py file like this: INSTALLED_APPS = ( … ‘django_extensions’, … ) urls.py … Read more

Get err_connection_refused accessing django running on wsl2 from Windows but can curl from Windows terminal

Seems like a forwarding problem. WSL2’s interface is NAT’d, whereas WSL1 was bridged by default. WSL seems to do some “auto-forwarding” of ports, but only on localhost. However, sometimes this auto-forwarding mechanism seems to “break down”. The main culprit seems to be hibernation or Windows Fast Startup (which are both closely-related features). Does the problem … Read more

How to register users in Django REST framework?

Django REST Framework 3 allow override create method in serializers: from rest_framework import serializers from django.contrib.auth import get_user_model # If used custom user model UserModel = get_user_model() class UserSerializer(serializers.ModelSerializer): password = serializers.CharField(write_only=True) def create(self, validated_data): user = UserModel.objects.create_user( username=validated_data[‘username’], password=validated_data[‘password’], ) return user class Meta: model = UserModel # Tuple of serialized model fields (see … Read more

Django error message “Add a related_name argument to the definition”

You have a number of foreign keys which django is unable to generate unique names for. You can help out by adding “related_name” arguments to the foreignkey field definitions in your models. Eg: content_type = ForeignKey(Topic, related_name=”topic_content_type”) See here for more. http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name

How do I migrate a model out of one django app and into a new one?

How to migrate using south. Lets say we got two apps: common and specific: myproject/ |– common | |– migrations | | |– 0001_initial.py | | `– 0002_create_cat.py | `– models.py `– specific |– migrations | |– 0001_initial.py | `– 0002_create_dog.py `– models.py Now we want to move model common.models.cat to specific app (precisely to … Read more

How can I restrict Django’s GenericForeignKey to a list of models?

For example, your apps are app and app2 and there are A, B models in app and there are C, D models in app2. you want to see only app.A and app.B and app2.C from django.db import models class TaggedItem(models.Model): tag = models.SlugField() limit = models.Q(app_label=”app”, model=”a”) | models.Q(app_label=”app”, model=”b”) | models.Q(app_label=”app2″, model=”c”) content_type = … Read more

Django user profile

You have to make a model for the user profile: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) location = models.CharField(max_length=140) gender = models.CharField(max_length=140) employer = models.ForeignKey(Employer) profile_picture = models.ImageField(upload_to=’thumbpath’, blank=True) def __unicode__(self): return u’Profile of user: %s’ % self.user.username Then configure in settings.py: AUTH_PROFILE_MODULE = ‘accounts.UserProfile’