Reputation: 9123
For example say I have a website called website.com
. When the url website.com/stackoverflow
is accessed for the first time, I want to store the value stackoverflow
in my database. Is this possible, and how would I do it?
Upvotes: 0
Views: 33
Reputation: 10305
use get_or_create and I assume you have defined model for Website
urls
url(r'^(?P<url_path>\w+)/$', views.home, name='detail'),
views
def home(request, url_path):
obj, created = Website.objects.get_or_create(path=url_path)
if created:
# Do something with created object
Upvotes: 1