How do I customize a user registration form so it only requires email and password fields?

2017-11-19 Thread Tom Tanner
I'm following this 
[tutorial](https://simpleisbetterthancomplex.com/tutorial/2017/02/18/how-to-create-user-sign-up-view.html)
 
on making simple registration forms in Django. I'd like to make a user 
registration form that requires only two fields: "Email" and "Password." No 
second password field, just one.

So far, My `views.py` looks like this: 

def register(request, template="register.html", redirect='/'):
if request.method=="POST":
form= RegisterForm(request.POST)
if form.is_valid():
form.save()
email= form.cleaned_data.get("email")
raw_password= form.cleaned_data.get("password1")
user= authenticate(email=email, password=raw_password)
login(request, user)
return redirect('/')
else:
form= RegisterForm()
return render(request, template, {"form": form})
 
`forms.py` has this class in it:

class RegisterForm(UserCreationForm):
email= forms.EmailField(label=_("Email"), max_length=254)

class Meta:
model= User
fields= ("email",)

`register.html` looks simple:

{% extends "base.html" %}
{% block main %}
Register

{% csrf_token %}
{{ form.as_p }}
Register

{% endblock main %}

In `urls.py`, I have this line in `urlpatterns`: `url("^register/$", 
views.register, name="register"),`.

But my registration forms looks like this, with an Email field and two 
Password fields: http://i.imgur.com/b359A5Z.png. And if I fill out all 
three fields and hit "Register," I get this error: `UNIQUE constraint 
failed: auth_user.username`.

Any idea why I'm getting this error? And how can I make sure my form only 
has two fields: Email and Password?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94d23f3b-25ee-437d-8302-ad80d6ecc1a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I customize a user registration form so it only requires email and password fields?

2017-11-20 Thread Tom Tanner
Hello Amitesh,

When you say to return HttpReponse(), how would that code look? And I'm 
still learning Django, but how would this make it so that the only required 
fields on my registration form are "email" and "password?"

Thanks.

On Sunday, November 19, 2017 at 11:30:51 PM UTC-5, Amitesh Sahay wrote:
>
> Hello Tom, 
>
> Django comes inbuilt with user authentication functions which is almost 
> more than enough in most of the requirements.
> In your case, you just need to import User model in models.py and in 
> views.py under "if" statement just return HttpResponse. You dont need to 
> write anything else. For email and password you don't need custom models 
> and views. 
>
> Amitesh
>
> Sent from Yahoo Mail on Android 
> <https://overview.mail.yahoo.com/mobile/?.src=Android>
>
> On Mon, Nov 20, 2017 at 8:50, Tom Tanner
> > wrote:
> I'm following this [tutorial](
> https://simpleisbetterthancomplex.com/tutorial/2017/02/18/how-to-create-user-sign-up-view.html)
>  
> on making simple registration forms in Django. I'd like to make a user 
> registration form that requires only two fields: "Email" and "Password." No 
> second password field, just one.
>
> So far, My `views.py` looks like this: 
>
> def register(request, template="register.html", redirect='/'):
> if request.method=="POST":
> form= RegisterForm(request.POST)
> if form.is_valid():
> form.save()
> email= form.cleaned_data.get("email")
> raw_password= form.cleaned_data.get("password1")
> user= authenticate(email=email, password=raw_password)
> login(request, user)
> return redirect('/')
> else:
> form= RegisterForm()
> return render(request, template, {"form": form})
>  
> `forms.py` has this class in it:
>
> class RegisterForm(UserCreationForm):
> email= forms.EmailField(label=_("Email"), max_length=254)
> 
> class Meta:
> model= User
> fields= ("email",)
>
> `register.html` looks simple:
>
> {% extends "base.html" %}
> {% block main %}
> Register
> 
> {% csrf_token %}
> {{ form.as_p }}
> Register
> 
> {% endblock main %}
>
> In `urls.py`, I have this line in `urlpatterns`: `url("^register/$", 
> views.register, name="register"),`.
>
> But my registration forms looks like this, with an Email field and two 
> Password fields: http://i.imgur.com/b359A5Z.png. And if I fill out all 
> three fields and hit "Register," I get this error: `UNIQUE constraint 
> failed: auth_user.username`.
>
> Any idea why I'm getting this error? And how can I make sure my form only 
> has two fields: Email and Password?
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/94d23f3b-25ee-437d-8302-ad80d6ecc1a1%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/94d23f3b-25ee-437d-8302-ad80d6ecc1a1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dd1dbb48-c624-4311-8726-22d405a3a8b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I customize a user registration form so it only requires email and password fields?

2017-11-20 Thread Tom Tanner
I changed a few things. 

`models.py` now has this:

class MyUser(AbstractBaseUser):
email= models.CharField(max_length=254, unique=True)
USERNAME_FIELD= "email"

`forms.py`"

class RegisterForm(UserCreationForm):
email= forms.EmailField(label=_("Email"), max_length=254)

class Meta:
model= MyUser
fields= ("email",)

`views.py`:

def register(request, template="register.html", redirect='/'):
if request.method=="POST":
form= RegisterForm(request.POST)
if form.is_valid():
form.save()
email= form.cleaned_data.get("email")
raw_password= form.cleaned_data.get("password1")
user= authenticate(username=email, password=raw_password)
login(request, user)
return redirect('/')
else:
form= RegisterForm()
return render(request, template, {"form": form})

The form looks the same when rendered, with one "Email" field and two 
password fields. But now when I try to register I get this error: 
`'AnonymousUser' object has no attribute '_meta'`. And when navigated back 
to the form and reentered the email I used, the page refreshed and put this 
message above the form: `"My user with this Email already exists."`.

So Django makes the user, but there's a problem with processing stuff after 
the user's creation, I guess?

On Monday, November 20, 2017 at 4:26:16 PM UTC-5, Tom Tanner wrote:
>
> Hello Amitesh,
>
> When you say to return HttpReponse(), how would that code look? And I'm 
> still learning Django, but how would this make it so that the only required 
> fields on my registration form are "email" and "password?"
>
> Thanks.
>
> On Sunday, November 19, 2017 at 11:30:51 PM UTC-5, Amitesh Sahay wrote:
>>
>> Hello Tom, 
>>
>> Django comes inbuilt with user authentication functions which is almost 
>> more than enough in most of the requirements.
>> In your case, you just need to import User model in models.py and in 
>> views.py under "if" statement just return HttpResponse. You dont need to 
>> write anything else. For email and password you don't need custom models 
>> and views. 
>>
>> Amitesh
>>
>> Sent from Yahoo Mail on Android 
>> <https://overview.mail.yahoo.com/mobile/?.src=Android>
>>
>> On Mon, Nov 20, 2017 at 8:50, Tom Tanner
>>  wrote:
>> I'm following this [tutorial](
>> https://simpleisbetterthancomplex.com/tutorial/2017/02/18/how-to-create-user-sign-up-view.html)
>>  
>> on making simple registration forms in Django. I'd like to make a user 
>> registration form that requires only two fields: "Email" and "Password." No 
>> second password field, just one.
>>
>> So far, My `views.py` looks like this: 
>>
>> def register(request, template="register.html", redirect='/'):
>> if request.method=="POST":
>> form= RegisterForm(request.POST)
>> if form.is_valid():
>> form.save()
>> email= form.cleaned_data.get("email")
>> raw_password= form.cleaned_data.get("password1")
>> user= authenticate(email=email, password=raw_password)
>> login(request, user)
>> return redirect('/')
>> else:
>> form= RegisterForm()
>> return render(request, template, {"form": form})
>>  
>> `forms.py` has this class in it:
>>
>> class RegisterForm(UserCreationForm):
>> email= forms.EmailField(label=_("Email"), max_length=254)
>> 
>> class Meta:
>> model= User
>> fields= ("email",)
>>
>> `register.html` looks simple:
>>
>> {% extends "base.html" %}
>> {% block main %}
>> Register
>> 
>> {% csrf_token %}
>> {{ form.as_p }}
>> Register
>> 
>> {% endblock main %}
>>
>> In `urls.py`, I have this line in `urlpatterns`: `url("^register/$", 
>> views.register, name="register"),`.
>>
>> But my registration forms looks like this, with an Email field and two 
>> Password fields: http://i.imgur.com/b359A5Z.png. And if I fill out all 
>> three fields and hit "Register," I get this error: `UNIQUE constraint 
>> failed: auth_user.username`.
>>
>> Any idea why I'm getting this error? And how can I make sure my form only 
>> has two fields: Email and Password?
>>
>> -- 
>> You received this message because you are subscribed to t

How do I make my form send a POST request to a specified view?

2017-11-23 Thread Tom Tanner
My page has a registration form at `"/login_register/"`. I want the form to 
send a POST request to `"/register/"`. Here's my code so far.

`urls.py`:
url("^login_register/$", views.login_register, name="login_register"),
url("^register/$", views.register, name="register"),


`views.py`:
def login_register(request, template="pages/login_register.html"):
 '''
 Display registration and login forms
 '''
 registration_form= RegisterForm()
 return render(request, template, {"registration_form": registration_form})


def register(request):
 '''
 Process user registration
 '''
 if request.method=="POST":
   # Some code here


`pages/login_register.html`:
 # For this example, I only include the registration form's HTML
 Register
 
 {% csrf_token %}
 {{ registration_form.as_p }}
 Register
 


When I hit "Register" on the form, my browser sends a POST request to 
"login_register/". I want it to send a POST request to "register/". How do 
I do this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/72030063-8482-4723-9f2c-b25b17656a43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I make my form send a POST request to a specified view?

2017-11-23 Thread Tom Tanner
Thanks, k2, this helped.

On Thursday, November 23, 2017 at 5:22:43 PM UTC-5, k2527806 wrote:
>
> login_register.html :
>
>  
>  {% csrf_token %}
>  {{ registration_form.as_p }}
>  Register
>  
>
>
> On Nov 24, 2017 1:42 AM, "Tom Tanner"  > wrote:
>
>> My page has a registration form at `"/login_register/"`. I want the form 
>> to send a POST request to `"/register/"`. Here's my code so far.
>>
>> `urls.py`:
>> url("^login_register/$", views.login_register, name="login_register"),
>> url("^register/$", views.register, name="register"),
>>
>>
>> `views.py`:
>> def login_register(request, template="pages/login_register.html"):
>>  '''
>>  Display registration and login forms
>>  '''
>>  registration_form= RegisterForm()
>>  return render(request, template, {"registration_form": registration_form
>> })
>>
>>
>> def register(request):
>>  '''
>>  Process user registration
>>  '''
>>  if request.method=="POST":
>># Some code here
>>
>>
>> `pages/login_register.html`:
>>  # For this example, I only include the registration form's HTML
>>  Register
>>  
>>  {% csrf_token %}
>>  {{ registration_form.as_p }}
>>  Register
>>  
>>
>>
>> When I hit "Register" on the form, my browser sends a POST request to 
>> "login_register/". I want it to send a POST request to "register/". How do 
>> I do this?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/72030063-8482-4723-9f2c-b25b17656a43%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/72030063-8482-4723-9f2c-b25b17656a43%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5eb78826-d762-4dc9-af12-915365af5f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I make Django show the "user already exists" message when someone tries to register with an existing username?

2017-11-23 Thread Tom Tanner
My `urls.py` has this:
url("^login_register/$", views.login_register, name="login_register"),
url("^register/$", views.register, name="register"),

`views.py` has this:
def login_register(request, template="pages/login_register.html"):
 '''
 Display registration and login forms
 '''
 registration_form= RegisterForm()
 return render(request, template, {"registration_form": registration_form})




def register(request):
 '''
 Process user registration
 '''
 if request.method=="POST":
  form= RegisterForm(request.POST)
  print form.is_valid()
  if form.is_valid():
   form.save()
   email= form.cleaned_data.get("email")
   raw_password= form.cleaned_data.get("password1")
   user= authenticate(username=email, password=raw_password)
   login(request, user)
   return redirect(home_slug())
 else:
  return redirect(reverse("login_register"))


`login_register.html` form HTML looks like this:
 Register
 
   {% csrf_token %}
   {{ registration_form.as_p }}
   Register
 


When I fill out registration with an email that already exists, I get this 
error: `ValueError: The view theme.views.register didn't return an 
HttpResponse object. It returned None instead.`. That's because when 
`form.is_valid()` is False, there is no return value. What do I need to 
return so that the message on the Registration form states the email 
already exists?


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/62069844-3db2-44b0-95b2-afde1abcd28b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I make Django show the "user already exists" message when someone tries to register with an existing username?

2017-11-24 Thread Tom Tanner
Thanks for replying. Looks like it'll be easier for me to combine these 
into one view.

On Thursday, November 23, 2017 at 7:13:16 PM UTC-5, Tom Tanner wrote:
>
> My `urls.py` has this:
> url("^login_register/$", views.login_register, name="login_register"),
> url("^register/$", views.register, name="register"),
>
> `views.py` has this:
> def login_register(request, template="pages/login_register.html"):
>  '''
>  Display registration and login forms
>  '''
>  registration_form= RegisterForm()
>  return render(request, template, {"registration_form": registration_form
> })
>
>
>
>
> def register(request):
>  '''
>  Process user registration
>  '''
>  if request.method=="POST":
>   form= RegisterForm(request.POST)
>   print form.is_valid()
>   if form.is_valid():
>form.save()
>email= form.cleaned_data.get("email")
>raw_password= form.cleaned_data.get("password1")
>user= authenticate(username=email, password=raw_password)
>login(request, user)
>return redirect(home_slug())
>  else:
>   return redirect(reverse("login_register"))
>
>
> `login_register.html` form HTML looks like this:
>  Register
>  
>{% csrf_token %}
>{{ registration_form.as_p }}
>Register
>  
>
>
> When I fill out registration with an email that already exists, I get this 
> error: `ValueError: The view theme.views.register didn't return an 
> HttpResponse object. It returned None instead.`. That's because when 
> `form.is_valid()` is False, there is no return value. What do I need to 
> return so that the message on the Registration form states the email 
> already exists?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/acd3f42f-9859-4c0c-8f00-e8147c0bbc2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How can I learn to make a user login?

2017-11-25 Thread Tom Tanner
I've read this tutorial 

 
on making a simple user registration form. But what about a form for just 
logging in existing users? I can make a registration form with `views.py` 
looking like this:

 registration_form.save()
 email= registration_form.cleaned_data.get("email")
 raw_password= registration_form.cleaned_data.get("password1")
 user= authenticate(username=email, password=raw_password)
 login(request, user)
 return redirect(home_slug())

Is there an example of how to make the backend for logging in users?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a99e8479-2a7a-4c64-b6bf-8c3f1e0d025f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I learn to make a user login?

2017-11-25 Thread Tom Tanner
I guess what I mean is...

What’s function do I need to use that:
A) logs in the user 
B) returns an error if there’s a problem logging in?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7b40c4d3-54fc-4f59-b577-6bd49fe12939%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I learn to make a user login?

2017-11-25 Thread Tom Tanner
To put it another way: Is there something like `UserCreationForm`, but for 
logging in users?

On Saturday, November 25, 2017 at 2:20:11 PM UTC-5, Tom Tanner wrote:
>
> I guess what I mean is... 
>
> What’s function do I need to use that: 
> A) logs in the user 
> B) returns an error if there’s a problem logging in?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/92c16e09-1af1-4a17-b749-b49e3af8819e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I learn to make a user login?

2017-11-25 Thread Tom Tanner
I see Django has an auth URLfor logging in. How do I construct the login 
form?

I have a template that will have both login and register forms on it. My 
view `login_register` looks something like this:

def login_register(request, template="pages/login_register.html"):
 '''
 Display registration and login forms.
 Process user registration.
 Process user login.
 '''
 if request.method=="POST":
  registration_form= UserCreationForm(request.POST)
  if registration_form.is_valid():
   registration_form.save()
   username = registration_form.cleaned_data.get("username")
   raw_password = registration_form.cleaned_data.get("password1")
   user = authenticate(username=username, password=raw_password)
   login(request, user)
   return redirect(home_slug())
  else:
   registration_form = UserCreationForm()
   return render(request, template, {"registration_form": registration_form
})

The template for this view:
 
  Log in
  
   {% csrf_token %}
   {{ login_form.as_p }}
  
 
 
  Register
  
   {% csrf_token %}
   {{ registration_form.as_p }}
   Register
  
 

It seems like `UserCreationForm` makes the register form. So how do I make 
the login form?

On Saturday, November 25, 2017 at 3:14:25 PM UTC-5, Daniel Roseman wrote:
>
> On Saturday, 25 November 2017 19:59:10 UTC, Tom Tanner wrote:
>>
>> To put it another way: Is there something like `UserCreationForm`, but 
>> for logging in users?
>>
>> On Saturday, November 25, 2017 at 2:20:11 PM UTC-5, Tom Tanner wrote:
>>>
>>> I guess what I mean is... 
>>>
>>> What’s function do I need to use that: 
>>> A) logs in the user 
>>> B) returns an error if there’s a problem logging in?
>>
>>
> Did you read the docs, where these are fully documented?
>
> https://docs.djangoproject.com/en/1.11/topics/auth/default/#module-django.contrib.auth.views
> --
> DR. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ac8ae345-b886-40e6-8c9f-fd1b6d75c54e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I limit my login form to just email and password?

2017-11-25 Thread Tom Tanner
My `models.py` has this:
class MyUser(AbstractBaseUser):
 email= models.CharField(max_length=254, unique=True)
 USERNAME_FIELD= "email"

My `forms.py` has this:
class LoginForm(AuthenticationForm):
 email= forms.EmailField(label=_("Email"), max_length=254)

 class Meta:
  model= MyUser
  fields= ("email",)

When a user goes to "/signin/", Django loads `sign_in.html`:
 Log in
 
  {% csrf_token %}
  {{ login_form.as_p }}
  Log in
 

The form on the template has three fields: Username, Password and Email, in 
that Order. I want only Email and Password to show up in the form. How do I 
do that?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4e9a3109-3dd0-4754-91f2-44731154920c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I limit my login form to just email and password?

2017-11-26 Thread Tom Tanner
Adding `exclude=["username"]` does nothing. Same if I replace "username" 
with "email" or "user".

On Sunday, November 26, 2017 at 2:44:44 PM UTC-5, Matemática A3K wrote:
>
>
>
> On Sun, Nov 26, 2017 at 12:55 AM, Tom Tanner  > wrote:
>
>> My `models.py` has this:
>> class MyUser(AbstractBaseUser):
>>  email= models.CharField(max_length=254, unique=True)
>>  USERNAME_FIELD= "email"
>>
>> My `forms.py` has this:
>> class LoginForm(AuthenticationForm):
>>  email= forms.EmailField(label=_("Email"), max_length=254)
>>
>>  class Meta:
>>   model= MyUser
>>   fields= ("email",)
>>
>> The form on the template has three fields: Username, Password and Email, 
>> in that Order. I want only Email and Password to show up in the form. How 
>> do I do that?
>>
>
> https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#selecting-the-fields-to-use
>  
>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/4e9a3109-3dd0-4754-91f2-44731154920c%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/4e9a3109-3dd0-4754-91f2-44731154920c%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5db6a84-e370-4ccf-8fb6-2d2486f88a60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Why does Django say my login form is invalid? How can I find out why Django thinks it is?

2017-11-28 Thread Tom Tanner
My `forms.py` looks like this. (I want user's email to be their login 
username. 
from django.utils.translation import ugettext_lazy as _

from django import forms
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User

class LoginForm(AuthenticationForm):
 username= forms.EmailField(label=_("Email"), max_length=254)


 class Meta:
 model= User
 fields= ("username",)

`views.py`:
def login_register(request, template="pages/login_register.html"):
 if request.method=="POST":
  login_form= LoginForm(request.POST)
  if login_form.is_valid():
   print "Login form valid"
   return redirect(home_slug())
  # else:
  #  print "Login invalid"
 else:
  login_form= LoginForm()
 return render(request, template, {"login_form": login_form})


`login_register.html`:
 
  {% csrf_token %}
  {{ login_form.as_p }}
  Log in
 

The login form accepts two fields labeled "Email" and "Password." But when 
I hit "Log in" button, the page just seems to refresh. If I uncomment the 
`print` statement, it prints, indicating that 
`login_form.is_valid()!=True`. Why does Django do this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1e861f42-2115-4377-848c-67c59d122610%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why does Django say my login form is invalid? How can I find out why Django thinks it is?

2017-11-29 Thread Tom Tanner
What would I need to change? 

I tried changing the ...
fields= ("username",)

... to ...
fields= ("username","email",)
or...
fields= ("email",)

Nothing seemed to change. the `login_form.is_valid()` still is `False`.

Sorry if the question is dumb, I'm still learning Django thru working with 
it.



On Wednesday, November 29, 2017 at 12:21:04 AM UTC-5, Matemática A3K wrote:
>
>
> class LoginForm(AuthenticationForm):
>>  username= forms.EmailField(label=_("Email"), max_length=254)
>>
>>
>>  class Meta:
>>  model= User
>>
>  
>
>>
>>  fields= ("username",)
>>
>>
> If you use "fields = ("username")" you are restricting the fields to just 
> that field, and the authentication form needs also password to be valid
>  
>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/1e861f42-2115-4377-848c-67c59d122610%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7dafbe54-6563-401b-9461-b857f9340d64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why does Django say my login form is invalid? How can I find out why Django thinks it is?

2017-11-29 Thread Tom Tanner
I removed that line, but nothing changed.

On Wednesday, November 29, 2017 at 11:58:28 PM UTC-5, Matemática A3K wrote:
>
>
>
> On Thu, Nov 30, 2017 at 12:35 AM, Tom Tanner  > wrote:
>
>> What would I need to change? 
>>
>> I tried changing the ...
>> fields= ("username",)
>>
>> ... to ...
>> fields= ("username","email",)
>> or...
>> fields= ("email",)
>>
>> Nothing seemed to change. the `login_form.is_valid()` still is `False`.
>>
>> Sorry if the question is dumb, I'm still learning Django thru working 
>> with it.
>>
>>
> Try not using fields at all, that will use the fields in AuthenticationForm
>  
>
>>
>>
>> On Wednesday, November 29, 2017 at 12:21:04 AM UTC-5, Matemática A3K 
>> wrote:
>>>
>>>
>>> class LoginForm(AuthenticationForm):
>>>>  username= forms.EmailField(label=_("Email"), max_length=254)
>>>>
>>>>
>>>>  class Meta:
>>>>  model= User
>>>>
>>>  
>>>
>>>>
>>>>  fields= ("username",)
>>>>
>>>>
>>> If you use "fields = ("username")" you are restricting the fields to 
>>> just that field, and the authentication form needs also password to be valid
>>>  
>>>
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to django-users...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/1e861f42-2115-4377-848c-67c59d122610%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/1e861f42-2115-4377-848c-67c59d122610%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/7dafbe54-6563-401b-9461-b857f9340d64%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/7dafbe54-6563-401b-9461-b857f9340d64%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c506fa03-09f7-4f69-b464-ec2d789baf65%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I customize registration form HTML?

2017-11-30 Thread Tom Tanner
The HTML for the user registration form looks like this:

 {% csrf_token %}
 {{ registration_form.as_p }}
 Register


I understand that the `registration_form.as_p` line automatically gives me 
the form's HTML. But I'd like to customize that HTML. For instance, I'd 
like the label text to be placeholders instead. How do I do this?

If it helps, `registration_form` is `UserCreationForm()`

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12490918-6d56-4079-ab53-9b8cb6f9fd9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I customize registration form HTML?

2017-12-01 Thread Tom Tanner
Where can I find all the options like {{ form.name }} ?

On Friday, December 1, 2017 at 9:27:21 AM UTC-5, yingi keme wrote:
>
>
>
> Yingi Kem
>
> On 1 Dec 2017, at 3:25 PM, yingi keme > 
> wrote:
>
> Intead of rendering it with the as_p. You can render them individually.
> ie
>
> {{form.name}}
> {{form.username}}
>
>  In the forms.py, in each of the fields, add widget attributes.
>
> def MyForm(forms.ModelForm):
> name = forms.CharField(label='name', 
> widget=forms.TextInput(attrs={'placeholder':'Name', 
> 'class':'yourInputFieldClassName'}))
>
>
>
> Yingi Kem
>
> On 1 Dec 2017, at 1:50 AM, Tom Tanner  > wrote:
>
> The HTML for the user registration form looks like this:
> 
>  {% csrf_token %}
>  {{ registration_form.as_p }}
>  Register
> 
>
> I understand that the `registration_form.as_p` line automatically gives me 
> the form's HTML. But I'd like to customize that HTML. For instance, I'd 
> like the label text to be placeholders instead. How do I do this?
>
> If it helps, `registration_form` is `UserCreationForm()`
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/12490918-6d56-4079-ab53-9b8cb6f9fd9b%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/12490918-6d56-4079-ab53-9b8cb6f9fd9b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e0b39886-e521-40aa-a28e-ebca5213d42b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Login form error not showing up for wrong username/password combo

2017-12-01 Thread Tom Tanner
I have this code in my login form.
 {% for field in login_form %}
  {{ field }}
  {% if field.errors %}
   {{ field.errors.as_text|cut:"* "|escape }}
  {% endif %} 
 {% endfor %}

The user must enter a valid email address in the "username" field. If the 
user enters a string not formatted like an email, I'll see this error in 
the `p` tag: "Enter a valid email address."

But if the user enters a bad email/password combo, nothing shows up. In my 
`views.py`, I have a section that looks something like
if login_form.is_valid:
  ...
else:
  print login_form.errors 

Here's what Django prints to console. "__all__Please enter a correct username and 
password. Note that both fields may be case-sensitive."

Why does the error print to console but not into my `p` tag?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f4dfcfa5-c687-439e-9e3a-8cb6f0b2c826%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Login form error not showing up for wrong username/password combo

2017-12-03 Thread Tom Tanner
That did it.

On Saturday, December 2, 2017 at 10:59:58 PM UTC-5, Constantine Covtushenko 
wrote:
>
> Hi Tom,
>
> It seems like your are trying to show error that relates to form rather to 
> particular field.
> I see '__all__' key in example from console.
>
> And you did not create any html tag to show such errors on the page.
> All I see that you printed just field specific errors.
>
> Probably you should print at the top of your form something like this:
> *{{ form.non_field_errors }}*
>
> Regards,
> Constantine C.
>
> On Sat, Dec 2, 2017 at 12:38 AM, Tom Tanner  > wrote:
>
>> I have this code in my login form.
>>  {% for field in login_form %}
>>   {{ field }}
>>   {% if field.errors %}
>>{{ field.errors.as_text|cut:"* "|escape }}
>>   {% endif %} 
>>  {% endfor %}
>>
>> The user must enter a valid email address in the "username" field. If the 
>> user enters a string not formatted like an email, I'll see this error in 
>> the `p` tag: "Enter a valid email address."
>>
>> But if the user enters a bad email/password combo, nothing shows up. In 
>> my `views.py`, I have a section that looks something like
>> if login_form.is_valid:
>>   ...
>> else:
>>   print login_form.errors 
>>
>> Here's what Django prints to console. "> class="errorlist">__all__Please 
>> enter a correct username and password. Note that both fields may be 
>> case-sensitive."
>>
>> Why does the error print to console but not into my `p` tag?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/f4dfcfa5-c687-439e-9e3a-8cb6f0b2c826%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/f4dfcfa5-c687-439e-9e3a-8cb6f0b2c826%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Sincerely yours,
> Constantine C
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5c2b680b-e544-4839-93d9-f00f8d274672%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I customize form error messages?

2017-12-03 Thread Tom Tanner
In my login form, I have this code:

 {% if login_form.non_field_errors %}
  {{ login_form.non_field_errors.as_text|cut:"* "|escape 
}}
 {% endif %}

If a user enters the wrong username/password combo, the error reads like 
this: 'Please enter a correct username and password. Note that both fields 
may be case-sensitive." I'd like to change this message and other error 
messages. How do I do this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0bcec941-56f1-4442-9436-2e7cb9411454%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I customize form error messages?

2017-12-03 Thread Tom Tanner
Nevermind, I figured out I needed to edit `forms.py`.

My custom login class...

class LoginForm(AuthenticationForm):
 error_messages= {
  "invalid_login": _("Incorrect %(username)s/password combo")
 }
 # more code here...
}


On Sunday, December 3, 2017 at 9:46:09 PM UTC-5, Tom Tanner wrote:
>
> In my login form, I have this code:
>
>  {% if login_form.non_field_errors %}
>   {{ login_form.non_field_errors.as_text|cut:"* 
> "|escape 
> }}
>  {% endif %}
>
> If a user enters the wrong username/password combo, the error reads like 
> this: 'Please enter a correct username and password. Note that both fields 
> may be case-sensitive." I'd like to change this message and other error 
> messages. How do I do this?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3ac863e5-c73b-4b86-ad40-9a30aa7dbe9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I customize the "username already exists" message?

2017-12-03 Thread Tom Tanner
My `forms.py` has a custom user-creation class...
class RegisterForm(UserCreationForm):
 error_messages= {
  "password_mismatch": _("Passwords do not match."),
 }

Which error message do I need to replace for when the user chooses a 
username that already exists?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ab10c9df-afcb-4b08-a69c-2c31a78d4a7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-06 Thread Tom Tanner
Here's a sample PostGIS query I use to get geometries within four points:

SELECT *
FROM myTable
WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.geom,
4326);


With this query, I can get all rows within those four points. How do I 
execute this query or similar queries in Django or GeoDjango?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-07 Thread Tom Tanner
Thanks for replying, Jani. I should mention My `geom` field is a 
MultiPolygon, so I can't use `from_bbox` it seems...

On Sunday, January 7, 2018 at 3:45:55 AM UTC-5, Jani Tiainen wrote:
>
> Something like following should work. Didn't checked if that actually 
> works.
>
> Mymodel.objects.filter(geom__inside=Polygon.from_bbox((x1,y1,x2,y2), 
> srid=1234))   
>
> On Sun, Jan 7, 2018 at 10:41 AM, Jani Tiainen  > wrote:
>
>> Hi,
>>
>> I didn't realize what you were asking for. :D
>>
>> Django has bunch of spatial queries, so you're looking some of those 
>> __inside, __within lookups. Coordinate transformations do happen 
>> automatically so you just need to provide srid for you "envelope".
>>
>> On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner > > wrote:
>>
>>> Here's a sample PostGIS query I use to get geometries within four points:
>>>
>>> SELECT *
>>> FROM myTable
>>> WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
>>> 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.geom
>>> ,4326);
>>>
>>>
>>> With this query, I can get all rows within those four points. How do I 
>>> execute this query or similar queries in Django or GeoDjango?
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com .
>>> To post to this group, send email to django...@googlegroups.com 
>>> .
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient before...
>>
>
>
>
> -- 
> Jani Tiainen
>
> - Well planned is half done, and a half done has been sufficient before...
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ab0234b5-109b-4833-b223-c12870cb654d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-07 Thread Tom Tanner
I get this error when trying Jani's example: "FieldError: Unsupported 
lookup 'inside' for MultiPolygonField or join on the field not permitted."

On Sunday, January 7, 2018 at 7:33:51 PM UTC-5, Tom Tanner wrote:
>
> Thanks for replying, Jani. I should mention My `geom` field is a 
> MultiPolygon, so I can't use `from_bbox` it seems...
>
> On Sunday, January 7, 2018 at 3:45:55 AM UTC-5, Jani Tiainen wrote:
>>
>> Something like following should work. Didn't checked if that actually 
>> works.
>>
>> Mymodel.objects.filter(geom__inside=Polygon.from_bbox((x1,y1,x2,y2), 
>> srid=1234))   
>>
>> On Sun, Jan 7, 2018 at 10:41 AM, Jani Tiainen  wrote:
>>
>>> Hi,
>>>
>>> I didn't realize what you were asking for. :D
>>>
>>> Django has bunch of spatial queries, so you're looking some of those 
>>> __inside, __within lookups. Coordinate transformations do happen 
>>> automatically so you just need to provide srid for you "envelope".
>>>
>>> On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner  
>>> wrote:
>>>
>>>> Here's a sample PostGIS query I use to get geometries within four 
>>>> points:
>>>>
>>>> SELECT *
>>>> FROM myTable
>>>> WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
>>>> 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.
>>>> geom,4326);
>>>>
>>>>
>>>> With this query, I can get all rows within those four points. How do I 
>>>> execute this query or similar queries in Django or GeoDjango?
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to django-users...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Jani Tiainen
>>>
>>> - Well planned is half done, and a half done has been sufficient 
>>> before...
>>>
>>
>>
>>
>> -- 
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient before...
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/67a80f04-1ea1-45b7-bfce-76863ae0f13e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-08 Thread Tom Tanner
Nah, didn't seem to work either. I ended up going with 
`.execute()`: 
https://docs.djangoproject.com/en/2.0/topics/db/sql/#executing-custom-sql-directly

On Sunday, January 7, 2018 at 11:49:16 PM UTC-5, Jani Tiainen wrote:
>
> Hi.
>
> __within is probably correct lookup. 
>
> You can find all lookups at:  
> https://docs.djangoproject.com/en/2.0/ref/contrib/gis/geoquerysets/
>
> 8.1.2018 2.36 "Tom Tanner" > 
> kirjoitti:
>
>> I get this error when trying Jani's example: "FieldError: Unsupported 
>> lookup 'inside' for MultiPolygonField or join on the field not permitted."
>>
>> On Sunday, January 7, 2018 at 7:33:51 PM UTC-5, Tom Tanner wrote:
>>>
>>> Thanks for replying, Jani. I should mention My `geom` field is a 
>>> MultiPolygon, so I can't use `from_bbox` it seems...
>>>
>>> On Sunday, January 7, 2018 at 3:45:55 AM UTC-5, Jani Tiainen wrote:
>>>>
>>>> Something like following should work. Didn't checked if that actually 
>>>> works.
>>>>
>>>> Mymodel.objects.filter(geom__inside=Polygon.from_bbox((x1,y1,x2,y2), 
>>>> srid=1234))   
>>>>
>>>> On Sun, Jan 7, 2018 at 10:41 AM, Jani Tiainen  wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I didn't realize what you were asking for. :D
>>>>>
>>>>> Django has bunch of spatial queries, so you're looking some of those 
>>>>> __inside, __within lookups. Coordinate transformations do happen 
>>>>> automatically so you just need to provide srid for you "envelope".
>>>>>
>>>>> On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner  
>>>>> wrote:
>>>>>
>>>>>> Here's a sample PostGIS query I use to get geometries within four 
>>>>>> points:
>>>>>>
>>>>>> SELECT *
>>>>>> FROM myTable
>>>>>> WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
>>>>>> 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.
>>>>>> geom,4326);
>>>>>>
>>>>>>
>>>>>> With this query, I can get all rows within those four points. How do 
>>>>>> I execute this query or similar queries in Django or GeoDjango?
>>>>>>
>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "Django users" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to django-users...@googlegroups.com.
>>>>>> To post to this group, send email to django...@googlegroups.com.
>>>>>> Visit this group at https://groups.google.com/group/django-users.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>>> Jani Tiainen
>>>>>
>>>>> - Well planned is half done, and a half done has been sufficient 
>>>>> before...
>>>>>
>>>>
>>>>
>>>>
>>>> -- 
>>>> Jani Tiainen
>>>>
>>>> - Well planned is half done, and a half done has been sufficient 
>>>> before...
>>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/67a80f04-1ea1-45b7-bfce-76863ae0f13e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/67a80f04-1ea1-45b7-bfce-76863ae0f13e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b4623f71-52c7-4cd0-8dba-8e2e770875dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I make a Django model from a tab-delimited data file?

2018-01-08 Thread Tom Tanner
I have a tab-delimited data file that looks something like this:


NAME S1903_C02_001E state county tract State-County-Tract-ID
Census Tract 201, Autauga County, Alabama 66000 01 001 020100 01001020100
Census Tract 202, Autauga County, Alabama 41107 01 001 020200 01001020200
Census Tract 203, Autauga County, Alabama 51250 01 001 020300 01001020300

I want to make a Django model named `MyModel` with three columns: "name", 
"data", and "geoid", which correspond to the file's columns "NAME", 
"S1903_C02_001E", and "State-County-Tract-ID." Can I do this via command 
line, or with a custom Python script? I'm running my Django project locally 
on a computer running Debian 9.3. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/389d8f38-6dbc-43a0-8a69-d20aa13ca844%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I make a Django model from a tab-delimited data file?

2018-01-10 Thread Tom Tanner
Thanks you two. I'll check out that parser.

On Monday, January 8, 2018 at 9:38:44 PM UTC-5, Tom Tanner wrote:
>
> I have a tab-delimited data file that looks something like this:
>
>
> NAME S1903_C02_001E state county tract State-County-Tract-ID
> Census Tract 201, Autauga County, Alabama 66000 01 001 020100 01001020100
> Census Tract 202, Autauga County, Alabama 41107 01 001 020200 01001020200
> Census Tract 203, Autauga County, Alabama 51250 01 001 020300 01001020300
>
> I want to make a Django model named `MyModel` with three columns: "name", 
> "data", and "geoid", which correspond to the file's columns "NAME", 
> "S1903_C02_001E", and "State-County-Tract-ID." Can I do this via command 
> line, or with a custom Python script? I'm running my Django project locally 
> on a computer running Debian 9.3. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3437a3bc-6a71-4a21-a410-7ede182cb83d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


I plan to have lots of data tables with similar structure. How do you recommend I model them?

2018-01-10 Thread Tom Tanner
Hey everyone,

I have a bunch of text files that each have a bunch of columns in common. I 
plan to import these files into PostgreSQL tables. The website user will be 
able to send a GET request to query a table and get back data from it. 
Since most of the tables will have a bunch of columns in common, how should 
I structure them in my `models.py`?

Here's a couple examples of tab-delimited text files I'll import.

NAME S1903_C02_001E state county tract State-County-Tract-ID
Census Tract 201, Autauga County, Alabama 66000 01 001 020100 
01001020100
Census Tract 202, Autauga County, Alabama 41107 01 001 020200 
01001020200
Census Tract 203, Autauga County, Alabama 51250 01 001 020300 
01001020300



and 

NAME S1903_C02_001F S1903_C02_001G state county tract State-County-Tract
-ID
Census Tract 201, Autauga County, Alabama 66000 4040 01 001 020100 
01001020100
Census Tract 202, Autauga County, Alabama 41107 192837 01 001 020200 
01001020200
Census Tract 203, Autauga County, Alabama 51250 39482 01 001 020300 
01001020300


As you can see, they have several columns in common. I wouldn't want to 
repeat myself in `models.py` by listing the same columns over and over.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e5fc9dab-c0aa-4fb8-a66c-5f507a18f4b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Two command-line questions. How do I get a list of model names? How do I match a user-inputted string with a model name?

2018-01-17 Thread Tom Tanner
I've got the following in `management/commands/my_command.py`:

from django.core.management.base import BaseCommand, CommandError
from django.conf import settings

import os.path, csv

from theme.models import *
 
class Command(BaseCommand):
  def handle(self, *args, **options):
   modelName= raw_input("Enter model name: ")
   print "you entered", modelName


I want to show the user a list of all model names. I want to take the 
user's input and see if's an existing model. How do I do this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2d5a05da-27e1-40ba-9884-478aecb2efe5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I set the value of a model object's property after using `get_field()`?

2018-01-21 Thread Tom Tanner
I'm making a terminal command for my Django app:

from django.core.management.base import BaseCommand, CommandError
from django.core.exceptions import FieldDoesNotExist
from django.apps import apps


class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
"--app",
dest="app",
required=True,
)

parser.add_argument(
"--model",
dest="model",
required=True,
)

parser.add_argument(
"--col",
dest="col",
required=True,
)

def handle(self, *args, **options):
app_label = options.get('app')
model_name = options.get('model')
column_name = options.get('col')

try:
model = apps.get_model(app_label=app_label, model_name=
model_name)
except LookupError as e:
msg = 'The model "%s" under the app "%s" does not exist!' \
  % (model_name, app_label)
raise CommandError(msg)
try:
column = model._meta.get_field(column_name)
except FieldDoesNotExist as e:
msg = 'The column "%s" does not match!' % column_name
raise CommandError(msg)
else:
print(column, type(column))
# Do stuff here with the column, model.


Right now, `column` is ``. I want this instance of `model` to have `column_name` set to 
`100`. How can I set and save this instance in this manner?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2caa4cd5-cb62-4bee-8e41-6182bfba792a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I set the value of a model object's property after using `get_field()`?

2018-01-22 Thread Tom Tanner
Darn, is this possible with a new object of the model? My idea is to in the 
end let the user input information that will be made into a new record to 
add to the model. But I need the user to type in the model they want to 
use...

On Monday, January 22, 2018 at 1:09:53 PM UTC-5, Andrew Standley wrote:
>
> Hey Tom,
> First you'll need to create or get a particular instance of your model 
> using one of it's managers  `model.objects` and a query. Ex for a model 
> with a unique 'name' charfield: `model_obj = 
> model.objects.get(name='MyObject')`
> You can then use the column_name to set that attribute on the instance 
> `setattr(model_obj, column_name) = 100` and finally save those changes 
> `model_obj.save()`
> See https://docs.djangoproject.com/en/1.11/topics/db/queries/#
> -Andrew
> On 1/21/2018 9:44 PM, Tom Tanner wrote:
>
> I'm making a terminal command for my Django app:
>
> from django.core.management.base import BaseCommand, CommandError
> from django.core.exceptions import FieldDoesNotExist
> from django.apps import apps
> 
> 
> class Command(BaseCommand):
> def add_arguments(self, parser):
> parser.add_argument(
> "--app",
> dest="app",
> required=True,
> )
> 
> parser.add_argument(
> "--model",
> dest="model",
> required=True,
> )
> 
> parser.add_argument(
> "--col",
> dest="col",
> required=True,
> )
> 
> def handle(self, *args, **options):
> app_label = options.get('app')
> model_name = options.get('model')
> column_name = options.get('col')
> 
> try:
> model = apps.get_model(app_label=app_label, model_name=
> model_name)
> except LookupError as e:
> msg = 'The model "%s" under the app "%s" does not exist!' 
> \
>   % (model_name, app_label)
> raise CommandError(msg)
> try:
> column = model._meta.get_field(column_name)
> except FieldDoesNotExist as e:
> msg = 'The column "%s" does not match!' % column_name
> raise CommandError(msg)
> else:
> print(column, type(column))
> # Do stuff here with the column, model.
>
>
> Right now, `column` is ` column_name>`. I want this instance of `model` to have `column_name` set to 
> `100`. How can I set and save this instance in this manner?
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at *MailScanner has detected definite fraud in the 
> website at "groups.google.com". Do not trust this website:* *MailScanner 
> has detected definite fraud in the website at "groups.google.com". Do not 
> trust this website:* https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit *MailScanner has detected 
> definite fraud in the website at "groups.google.com". Do not trust this 
> website:* *MailScanner has detected definite fraud in the website at 
> "groups.google.com". Do not trust this website:* 
> https://groups.google.com/d/msgid/django-users/2caa4cd5-cb62-4bee-8e41-6182bfba792a%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/2caa4cd5-cb62-4bee-8e41-6182bfba792a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit *MailScanner has detected definite fraud in the 
> website at "groups.google.com". Do not trust this website:* *MailScanner 
> has detected definite fraud in the website at "groups.google.com". Do not 
> trust this website:* https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
>
> -- 
> This message has been scanned for viruses and dangerous content by 
> *E.F.A. Project* <http://www.efa-project.org>, and is believed to be 
> clean. 
> Click here to report this message as spam. 
> <http://lsefa1.linear-systems.com/cgi-bin/learn-msg.cgi?id=D18A7100A34.A4

Re: How do I set the value of a model object's property after using `get_field()`?

2018-01-23 Thread Tom Tanner
Hey Dylan, sorry again. My situation is a bit more complex. Let me try 
clarifying...

I have...
obj = apps.get_model(app_label="myApp", model_name="myModel")

But I cannot do...
obj.setattr()

I may be going about this wrong, but my script asks the user to type the 
name of the model they want to access into the terminal, hence the `obj` 
line. Then the script asks the user to type in the column name they want to 
access. So if the user inputs "myColumn", I'd like to be able to do 
something like `obj.myColumn = "Some value"`. Is this possible, or am I on 
the wrong track?

On Monday, January 22, 2018 at 9:02:46 PM UTC-5, Dylan Reinhold wrote:
>
> Andrew,
>You do not to get the field with _meta.get_field just use setattr which 
> takes a string as the field name.
> Now if you are creating a new instance of your model and are just passing 
> a single field all other fields would need to have defaults or be null=True.
>
> In your do stuff area you can just run this to create a new object with 
> the string 'Test Text':
>
> model_instance = model()
> setattr(model_instance, column_name, 'Test Text')
> model_instance.save()
>
>  
> Dylan
>
>
> On Mon, Jan 22, 2018 at 5:32 PM, Tom Tanner  > wrote:
>
>> Darn, is this possible with a new object of the model? My idea is to in 
>> the end let the user input information that will be made into a new record 
>> to add to the model. But I need the user to type in the model they want to 
>> use...
>>
>>
>> On Monday, January 22, 2018 at 1:09:53 PM UTC-5, Andrew Standley wrote:
>>
>>> Hey Tom,
>>> First you'll need to create or get a particular instance of your 
>>> model using one of it's managers  `model.objects` and a query. Ex for a 
>>> model with a unique 'name' charfield: `model_obj = 
>>> model.objects.get(name='MyObject')`
>>> You can then use the column_name to set that attribute on the instance 
>>> `setattr(model_obj, column_name) = 100` and finally save those changes 
>>> `model_obj.save()`
>>> See https://docs.djangoproject.com/en/1.11/topics/db/queries/#
>>> -Andrew
>>> On 1/21/2018 9:44 PM, Tom Tanner wrote:
>>>
>>> I'm making a terminal command for my Django app:
>>>
>>> from django.core.management.base import BaseCommand, CommandError
>>> from django.core.exceptions import FieldDoesNotExist
>>> from django.apps import apps
>>> 
>>> 
>>> class Command(BaseCommand):
>>> def add_arguments(self, parser):
>>> parser.add_argument(
>>> "--app",
>>> dest="app",
>>> required=True,
>>> )
>>> 
>>> parser.add_argument(
>>> "--model",
>>> dest="model",
>>> required=True,
>>> )
>>> 
>>> parser.add_argument(
>>> "--col",
>>> dest="col",
>>> required=True,
>>> )
>>> 
>>> def handle(self, *args, **options):
>>> app_label = options.get('app')
>>> model_name = options.get('model')
>>> column_name = options.get('col')
>>> 
>>> try:
>>> model = apps.get_model(app_label=app_label, model_name=
>>> model_name)
>>> except LookupError as e:
>>> msg = 'The model "%s" under the app "%s" does not 
>>> exist!' \
>>>   % (model_name, app_label)
>>> raise CommandError(msg)
>>> try:
>>> column = model._meta.get_field(column_name)
>>> except FieldDoesNotExist as e:
>>> msg = 'The column "%s" does not match!' % column_name
>>> raise CommandError(msg)
>>> else:
>>> print(column, type(column))
>>> # Do stuff here with the column, model.
>>>
>>>
>>> Right now, `column` is `>> column_name>`. I want this instance of `model` to have `column_name` set to 
>>> `100`. How can I set and save this instance in this manner?
>>> -- 
>>> Y

unbound method save() must be called with MyModel instance as first argument

2018-01-23 Thread Tom Tanner
I'm using `setattr()` to set attributes of a new object of a Django model.

obj = apps.get_model(app_label="theme", model_name="MyModel")
setattr(obj,"myCol",100)
obj.save()


I got this error: `TypeError: unbound method save() must be called with 
DataPopulationTracts2016 instance as first argument (got nothing instead)`.

I want to save the new instance of `MyModel` to the model, using 
`get_model()` and `setattr()` to make a new instance of the model and set 
its attributes. How do I make `get_model()` and `setattr()` work with 
`save()`?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d1e137f5-c415-45e2-9d7c-965fb3a3eb02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: unbound method save() must be called with MyModel instance as first argument

2018-01-23 Thread Tom Tanner
In my case, I'm using `setattr()` because I need to access a field via 
string and set it. I can't do `obj.myCol = "blah blah"` because this whole 
code is part of a `manage.py` command I'm setting up that asks the user to 
input the name of the model and column they want to add a new record for.

On Tuesday, January 23, 2018 at 7:59:11 PM UTC-5, Costja Covtushenko wrote:
>
> Hi,
>
> It looks like with get_model() you’ve gotten Model class not Model 
> instance.
> You can use `save()` on instance only.
> You need to have something like:
>
> class_ = get_model(…)
> instance = class_()
> instance.save()
>
> I hope that make sense to you.
>
> Regards,
> C.
>
> On Jan 23, 2018, at 7:43 PM, Tom Tanner  > wrote:
>
> get_model
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f06c409b-ca0a-4350-8736-26ad0553ab67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I convert an existing column to Foreign Key?

2018-01-29 Thread Tom Tanner
I have two models `model_a` and `model_b`, where their tables look 
something like this...


Table `a` looks something like this -- first row is column names, both 
contain characters:

id |  tractce   | someString
2  |  "0011900" | "Label here"

Table `b`:

id | tractFIPS
1  | "0011900"



Here's code from `models.py`:

class model_a(models.Model):
tractce = models.CharField(max_length=6)
someString = models.TextField()


class model_b(models.Model):
tractFIPS = models.CharField(max_length=6)



I want to convert `model_b` so that the `tractFIPS` field is a foreign key 
referencing `model_a`. Something like this I guess...

class model_b(models.Model):
tractFIPS_FK = models.ForeignKey(model_a)



And the table for `model_b` would look something like this in the end:

id |  tractFIPS_FK_id
1  |  2


How do I convert `model_b`'s `tractFIPS` field to a foreign key with the 
correct values in them? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a347bdbc-9cd7-4cda-a0f6-873812c360e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I move a project from one computer to another?

2018-02-12 Thread Tom Tanner
I have a Django project that I want to work on with another computer. Do I 
need to backup my current project's Postgres database and restore it on the 
other computer's Postgres database to get my project up and running there? 
Or is there a Django way to do this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5ab2022-4fd1-4f8f-bb40-d4194bbf397f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Noob question: Is the User model compatible with subscription-style website?

2018-02-14 Thread Tom Tanner
I'm working on a Django-powered subscription website with a Django-powered 
CMS backend. Can the User model, or a derived class, be made to be 
compatible with this idea? In my case, I want to store a user's username, 
password, and subscription ID. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/da4f96f9-95cd-4b23-b4d2-842ef3649226%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Stripe problem: InvalidRequestError: This customer has no attached payment source

2018-02-18 Thread Tom Tanner
I've been following the Quickstart guides from Stripe.

https://stripe.com/docs/quickstart

https://stripe.com/docs/subscriptions/quickstart


This is what my form looks like:


{% csrf_token %}
{% for field in registration_form %}
{{ field }}
{% if field.errors %}
{{ field.errors.as_text|cut:"* 
"|escape }}
{% endif %} 
{% endfor %}
{% if registration_form.non_field_errors %}
{{ 
registration_form.non_field_errors.as_text|cut:"* "|escape }}
{% endif %}


  


Register


var displayError=   document.getElementById('card-errors');
var stripe= Stripe("pk_test_BjhejGz5DZNcSHUVaqoipMtF");
var elements=   stripe.elements();

var style=  {
base: {
fontSize: "1.1875rem",
fontSmoothing: "always",
fontWeight: "600"
}
};

var card=   elements.create("card",{style:style});
card.mount("#card-element");
card.addEventListener('change', function(event) {

if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});

var formID= "register-form";
var form=   document.getElementById(formID);
form.addEventListener("submit",function(event){
event.preventDefault();

stripe.createToken(card).then(function(result){
if(result.error) {
displayError.textContent=   result.error.message;
} else {
stripeTokenHandler(result.token, formID);
}   
})
});
// tut 
https://stripe.com/docs/stripe-js/elements/quickstart#create-form
function stripeTokenHandler(token, formID) {
// Insert the token ID into the form so it gets submitted 
to the server
var form = document.getElementById(formID);
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}





Then my `views.py` has this:

 if registration_form.is_valid():
  stripe.api_key= "sk_test_8rdFokhVsbsJJysHeKgyrMTc"
  stripeCustomer= stripe.Customer.create(
   email=request.POST["username"],
  )
  subscription= stripe.Subscription.create(
   customer=stripeCustomer["id"],
   items=[{"plan":"plan_CLFfBrRAKl7TRt"}],
  )



This gives me an error:


Internal Server Error: /login-register/
Traceback (most recent call last):
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/django/core/handlers/exception.py"
, line 42, in inner
response = get_response(request)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/django/core/handlers/base.py"
, line 249, in _legacy_get_response
response = self._get_response(request)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/django/core/handlers/base.py"
, line 178, in _get_response
response = middleware_method(request, callback, callback_args, 
callback_kwargs)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/mezzanine/pages/middleware.py"
, line 98, in process_view
return view_func(request, *view_args, **view_kwargs)
  File 
"/home/myUserName/myDjangoProjectWithStripe/product_blog/theme/views.py", 
line 154, in login_register
items=[{"plan":"plan_CLFfBrRAKl7TRt"}],
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_resources/subscription.py"
, line 33, in create
return super(Subscription, cls).create(**params)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_resources/abstract/createable_api_resource.py"
, line 17, in create
response, api_key = requestor.request('post', url, params, headers)
  File 
"/home/myUserName/myDjangoProjectWithStripe/local/lib/python2.7/site-packages/stripe/api_requestor.py"
, line 153, in request
resp = self.interpret_response(rbody, rcode, rheaders)
  File 
"/home/myUserName/myDjangoProjectW

Attaching `ng-model` to Select widget gives "?undefined:undefined?" `option` value attribute

2018-02-19 Thread Tom Tanner
How do I solve this problem with Django and AngularJS where the first 
`option` on my `select` tag displays wrong? Full info: 
https://stackoverflow.com/questions/48872768/attaching-ng-model-to-select-widget-gives-undefinedundefined-option-val

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9e8e8299-70a3-43dd-b3ce-eb043335c776%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I set up an AngularJS-driven form to work with Django password reset functionality?

2018-03-13 Thread Tom Tanner
I'm working on a web page with AngularJS v1.5.6. This page has other forms. 
I want to add a "Reset password" form to this page.

I've seen this Django password reset for tutorial: 
https://simpleisbetterthancomplex.com/tutorial/2016/09/19/how-to-create-password-reset-view.html.
 
But I'm unsure how I'd apply it to my situation.

My questions is how would I set up urls.py and views.py to handle this?

Here's the example code on 
StackOverflow: 
https://stackoverflow.com/questions/49265097/how-do-i-set-up-an-angularjs-driven-form-to-work-with-django-password-reset-func

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/33acd11a-6a05-4d50-88c4-be93268e417f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I use `password_reset_confirm.html` with AngularJS?

2018-03-21 Thread Tom Tanner


I want to integrate AngularJS in my custom password_reset_confirm.html template 
in Django. But when I fill out a new password and hit "submit," nothing 
happens.

Here's more info in better 
formatting: 
https://stackoverflow.com/questions/49396333/how-do-i-use-password-reset-confirm-html-with-angularjs

Can anyone help?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a6e87b9e-cc33-4604-a669-bf353f5b0923%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Trying to understand two messages from `manage.py check --deploy`

2018-04-23 Thread Tom Tanner
I get these two messages after running `python manage.py check --deploy`

?: (security.W001) You do not have 
'django.middleware.security.SecurityMiddleware' in your MIDDLEWARE_CLASSES 
so the SECURE_HSTS_SECONDS, SECURE_CONTENT_TYPE_NOSNIFF, 
SECURE_BROWSER_XSS_FILTER, and SECURE_SSL_REDIRECT settings will have no 
effect.
?: (security.W019) You have 
'django.middleware.clickjacking.XFrameOptionsMiddleware' in your 
MIDDLEWARE_CLASSES, but X_FRAME_OPTIONS is not set to 'DENY'. The default 
is 'SAMEORIGIN', but unless there is a good reason for your site to serve 
other parts of itself in a frame, you should change it to 'DENY'.

I do not understand what each of them mean or if I should be worried. Can 
anyone translate these to plain English?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1c0b2ca2-644c-4eac-9494-d3239e22f220%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I move my development data tables to production server?

2018-04-23 Thread Tom Tanner
Hey all, I have a bunch of tables on my local Django project. I set up the 
project on my production server and ran `manage.py migrate`. That set up 
the tables, but now I want to move the rows from my local tables to the 
ones on the production server. Both local and production server use 
Postgres. Is there a Django way to move the table data to production?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f65cd8eb-6399-4ee7-8830-84b19ea9b689%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


400 error, nginx debug log confusion, Django app

2018-05-11 Thread Tom Tanner
Note: `mydomain.com` is not my real domain name.

When I go to `test.mydomain.com`, I get a page that just says `Bad Request 
(400)`. 

I'm running a Django app located at `/home/django/product_blog`.

Here are the contents of my nginx file at 
`/etc/nginx/sites-available/BRBR2`.

server {
listen 80;
server_name test.mydomain.com;
error_log /var/log/nginx/debug.log debug;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/django/product_blog;
}

location / {
include uwsgi_params;
uwsgi_pass  
unix:/home/django/product_blog/product_blog.sock;
}
}

When I go to the debug file after trying to load the site, I see this: 
https://pastebin.com/GchPd1MD.

The file at `/var/log/nginx/error.log` shows nothing.

How do I find the source of the 400 error?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c8f497b0-8d9c-4695-a1ff-39abddc90bf5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 400 error, nginx debug log confusion, Django app

2018-05-11 Thread Tom Tanner
I ran `sudo reboot` and `sudo service nginx configtest && sudo service 
nginx restart`. Now the site loads just fine. I don't know which of those 
two commands did it.

On Friday, May 11, 2018 at 12:22:11 PM UTC-4, Tom Tanner wrote:
>
> Note: `mydomain.com` is not my real domain name.
>
> When I go to `test.mydomain.com`, I get a page that just says `Bad 
> Request (400)`. 
>
> I'm running a Django app located at `/home/django/product_blog`.
>
> Here are the contents of my nginx file at 
> `/etc/nginx/sites-available/BRBR2`.
>
> server {
> listen 80;
> server_name test.mydomain.com;
> error_log /var/log/nginx/debug.log debug;
> 
> location = /favicon.ico { access_log off; log_not_found off; }
> location /static/ {
> root /home/django/product_blog;
> }
> 
> location / {
> include uwsgi_params;
> uwsgi_pass  
> unix:/home/django/product_blog/product_blog.sock;
> }
> }
>
> When I go to the debug file after trying to load the site, I see this: 
> https://pastebin.com/GchPd1MD.
>
> The file at `/var/log/nginx/error.log` shows nothing.
>
> How do I find the source of the 400 error?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f51f5b16-59d5-438d-8cd8-27f8264ad5c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


IOError when trying to send email in Django app

2018-05-11 Thread Tom Tanner
I have a Django app running on a server with uWSGI and nginx. 

In my `local_settings.py` file I have this:

###
# EMAIL SETUP #
###
EMAIL_HOST = 'smtp.privateemail.com'
EMAIL_HOST_USER = 'supp...@mydomain.com'
EMAIL_HOST_PASSWORD = 'MY EMAIL PASSWORD'
EMAIL_PORT = 587
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True



# OTHER EMAIL SETTINGS #

ADMIN_EMAIL = "ad...@mydomain.com"
SUPPORT_EMAIL = "supp...@mydomain.com"


When I fill out the `/password_reset/` template with an email and submit 
the form, the email I enter gets no email. 

I see these lines in my `uwsgi.log` file after I submit the password reset 
form.

Fri May 11 17:48:10 2018 - SIGPIPE: writing to a closed pipe/socket/fd 
(probably the client disconnected) on request /password_reset/ (ip 
73.49.35.42) !!!
Fri May 11 17:48:10 2018 - uwsgi_response_write_headers_do(): Broken 
pipe [core/writer.c line 248] during POST /password_reset/ (73.49.35.42)
IOError: write error

What error is this? Why won't the password reset email send?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5a50ba30-9709-48a9-a937-bd9afb8bbf30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Password reset in Django on nginx server writes to log file instead of sending email

2018-05-14 Thread Tom Tanner
I have a Django app running on a server with uWSGI and nginx. 

In my `local_settings.py` file I have this:

###
# EMAIL SETUP #
###
EMAIL_HOST = 'smtp.privateemail.com'
EMAIL_HOST_USER = 'supp...@mydomain.com'
EMAIL_HOST_PASSWORD = 'MY EMAIL PASSWORD'
EMAIL_PORT = 465
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True



# OTHER EMAIL SETTINGS #

ADMIN_EMAIL = "ad...@mydomain.com"
SUPPORT_EMAIL = "supp...@mydomain.com"


When I fill out the `/password_reset/` template with an email and submit 
the form, the address I enter gets no password-reset message. Nothing is 
logged to *error.log*. Here's what I see in *uwsgi.log*

[pid: 3354|app: 0|req: 1489/2206] 73.49.35.42 () {44 vars in 948 bytes} 
[Mon May 14 16:59:06 2018] GET /login-register/ => generated 7480 bytes in 
39 msecs (HTTP/1.1 200) 3 headers in 102 bytes (2 switches on core 0)
[pid: 3355|app: 0|req: 718/2207] 73.49.35.42 () {44 vars in 994 bytes} [
Mon May 14 16:59:14 2018] GET /password_reset/ => generated 3669 bytes in 38 
msecs (HTTP/1.1 200) 4 headers in 256 bytes (1 switches on core 0)
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: Password reset on Default
From: webmaster@localhost
To: email.to.send.password.re...@gmail.com
Date: Mon, 14 May 2018 16:59:16 -
Message-ID: <20180514165916.3354.5092@my-ubuntu-server-hostname.mydomain
.com>



Hello,

You received this email because a request was made to reset the password
.


If you requested this, go to the following page and choose a new 
password: https://127.0.0.1:8000/reset/MQ/4w6-efc1272e976075dfd881/

Your username: MyUsername

Thank you.




---
[pid: 3354|app: 0|req: 1490/2208] 73.49.35.42 () {52 vars in 1194 bytes} 
[Mon May 14 16:59:16 2018] POST /password_reset/ => generated 0 bytes in 22 
msecs (HTTP/1.1 302) 4 headers in 138 bytes (1 switches on core 0)
[pid: 3355|app: 0|req: 719/2209] 73.49.35.42 () {46 vars in 1035 bytes} 
[Mon May 14 16:59:16 2018] GET /password_reset/done/ => generated 2877 
bytes in 40 msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 
0)



What must I change so that Django will email the email I input in the 
`/password_reset` template?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e6dd4643-4692-42b0-adf7-670fc973ee71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


SMTPRecipientsRefused: Sender address rejected: not owned by user

2018-05-15 Thread Tom Tanner
I have a Django app running on a server with uWSGI and nginx. 

In my `local_settings.py` file I have this:

###
# EMAIL SETUP #
###
EMAIL_HOST = 'smtp.privateemail.com'
EMAIL_HOST_USER = 'supp...@mydomain.com'
EMAIL_HOST_PASSWORD = 'MY EMAIL PASSWORD'
EMAIL_PORT = 465
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True



# OTHER EMAIL SETTINGS #

ADMIN_EMAIL = "ad...@mydomain.com"
SUPPORT_EMAIL = "supp...@mydomain.com"
DEFAULT_FROM_EMAIL = ADMIN_EMAIL
SERVER_EMAIL = ADMIN_EMAIL

I run `python manage.py runserver` on my local machine in the Django 
project's virtual environment. I fill out the password reset form at 
`password_rest/` using the email `my.perso...@gmail.com` and submit it. I 
get this error.

SMTPRecipientsRefused: {u'my.perso...@gmail.com': (553, '5.7.1 
: Sender address rejected: not owned by user 
supp...@mydomain.com')}

My website's email provider is Namecheap.

Why do I get this error when testing on my local machine? What must I 
change/add to get rid of it?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c159b190-4604-4b2d-90d6-562f9b4950db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Iframe'd page in Django template can't find it's Javascript or CSS files, 404 error

2017-03-04 Thread Tom Tanner
In my `views.py`, I have one path render an html file:

def interactive(request):
if request.session.get('interactiveID') == None:
t= get_template('blank-interactive.html')
else:
interactive_template= 'interactive-' + str(request.session['id']) + 
'/index.html'
t= get_template(interactive_template)

return HttpResponse(t.render())

So `form.html` has an `` that requests `/interactive`, and 
`request.session['id']` is set to `1`. When the iframe requests 
`/interactive`, it loads `interactive-1/index.html`. The iframe loads the 
HTML from that page, but cannot get the JS file at 
`interactive-1/scripts/main.js`. 

When I check the terminal, I see this 404 error: `GET 
/interactive/scripts/main.js`. If it would just load 
`/interactive-1/scripts/main.js`, there would be no problem. But Django 
loads `/interactive-1/index.html`, but not 
`/interactive-1/scripts/main.js`. Same goes for the CSS and image assets, 
which are in CSS and image folders.

What do I need to change in Django for it to correctly load the JS, CSS, 
images and other assets?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d94bfa19-0250-4a90-93be-63e18889cb53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Iframe'd page in Django template can't find it's Javascript or CSS files, 404 error

2017-03-04 Thread Tom Tanner
>How are you referring to the assets in the template?

In `interactive/index.html`, in the `` tag, I have ``

On Saturday, March 4, 2017 at 8:55:22 AM UTC-5, Daniel Roseman wrote:
>
> On Saturday, 4 March 2017 13:30:37 UTC, Tom Tanner wrote:
>>
>> In my `views.py`, I have one path render an html file:
>>
>> def interactive(request):
>> if request.session.get('interactiveID') == None:
>> t= get_template('blank-interactive.html')
>> else:
>> interactive_template= 'interactive-' + str(request.session['id']) + 
>> '/index.html'
>> t= get_template(interactive_template)
>> 
>> return HttpResponse(t.render())
>>
>> So `form.html` has an `` that requests `/interactive`, and 
>> `request.session['id']` is set to `1`. When the iframe requests 
>> `/interactive`, it loads `interactive-1/index.html`. The iframe loads the 
>> HTML from that page, but cannot get the JS file at 
>> `interactive-1/scripts/main.js`. 
>>
>> When I check the terminal, I see this 404 error: `GET 
>> /interactive/scripts/main.js`. If it would just load 
>> `/interactive-1/scripts/main.js`, there would be no problem. But Django 
>> loads `/interactive-1/index.html`, but not 
>> `/interactive-1/scripts/main.js`. Same goes for the CSS and image assets, 
>> which are in CSS and image folders.
>>
>> What do I need to change in Django for it to correctly load the JS, CSS, 
>> images and other assets?
>>
>
> There's not really enough information here to answer your question. How 
> are you referring to the assets in the template? Why do you have a 
> different path for those assets? Note though that template paths and asset 
> paths have nothing whatsoever to do with each other.
> -- 
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a788ad6-a6bb-4586-8a89-681ceacb857c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.