Re: How can I integrate simple Custom login page in Django.......?

2012-10-15 Thread Jason Sibre
Hi,
Just a hunch, but it kinda smells like your web server isn't executing the CGI 
script.  I'd suggest checking into what is necessary to get your server to 
execute CGI, vs serving it up as text.


On Oct 15, 2012, at 5:40 AM, Pervez Mulla wrote:

> Instead of CGI server path , I places perl script in static folder and given 
> path for that . 
> 
> On Mon, Oct 15, 2012 at 4:09 PM, Pervez Mulla  wrote:
> responseText: #!/usr/bin/perl -T use CGI; use DBI; use strict; use warnings; 
> use netsharkusr; my $cgi = CGI->new; my $username = $cgi->param("username"); 
> my $password = $cgi->param("password"); my $tempuser = new netsharkusr(); 
> if($tempuser->readbyusername($username) eq 1) { if($tempuser->{username} eq 
> $username) { print "success \n"; #exit; } } #$password = "123go"; my $userid; 
> my $tempuser2 = new netsharkusr(); if($tempuser2->readbypassword($password)) 
> { if($tempuser2->{password} eq $password) { print "sccess \n"; $userid = 
> $tempuser2->{userID}; } } # check the username and password in the database # 
> create a JSON string according to the database result my $json = ($userid) ? 
> qq{{"success" : "login is successful", "userid" : $userid}} : qq{{"error" : 
> "username or password is wrong"}}; # return JSON string print 
> $cgi->header(-type => "application/json", -charset => "utf-8"); print $json;, 
> textStatus: parsererror, errorThrown: undefined
> 
> 
> On Mon, Oct 15, 2012 at 4:07 PM, Sergiy Khohlov  wrote:
> please provide error
> 
> 2012/10/15 Pervez Mulla :
> > On error note its printing all pelr script itself.
> >
> >
> > On Mon, Oct 15, 2012 at 3:31 PM, Sergiy Khohlov  wrote:
> >>
> >> please provide error message
> >>
> >> 2012/10/15 Pervez Mulla :
> >> > Thank You for your response Sergiy ,
> >> >
> >> > I already try'd to run this script as shown in Django DOC as u given
> >> > .but
> >> > still it didnt work:(
> >> >
> >> > Thank You
> >> > Pervez
> >> >
> >> > On Mon, Oct 15, 2012 at 1:28 PM, Sergiy Khohlov 
> >> > wrote:
> >> >>
> >> >>
> >> >> https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-LOGIN_URL
> >> >>
> >> >>  set this one in setting.py
> >> >>
> >> >> 2012/10/15 Pervez Mulla :
> >> >> > Hi,
> >> >> >
> >> >> > I have login.html , login,js ang login.pl.
> >> >> >
> >> >> > I want to integrate basic login page in Django with perl back-end
> >> >> > from
> >> >> > where
> >> >> > Am reading my DB.
> >> >> > I was trying to integrate it from last day but come out with empty
> >> >> > .There
> >> >> > might be some settings in setting.py.
> >> >> > Below is my code
> >> >> >
> >> >> > --
> >> >> > login.html
> >> >> > --
> >> >> > http://www.w3.org/1999/xhtml;>
> >> >> >   
> >> >> >  >> >> > />
> >> >> >  >> >> > src="jquery-1.7.2.min.js">
> >> >> > 
> >> >> > 
> >> >> >   #loginContent { width: 350px; margin: 100px auto; }
> >> >> >   button[type] { margin: 0.5em 0; }
> >> >> > label {font-weight:bold;}
> >> >> > fieldset {padding:0 1.4em 1.4em 1.4em;margin:0 0 1.5em 0;border:1px
> >> >> > solid
> >> >> > #ccc;}
> >> >> > legend
> >> >> >
> >> >> > {font-weight:bold;font-size:1.2em;margin-top:-0.2em;margin-bottom:1em;}
> >> >> > fieldset, #IE8#HACK {padding-top:1.4em;}
> >> >> > legend, #IE8#HACK {margin-top:0;margin-bottom:0;}
> >> >> > input[type=text], input[type=password], input.text, input.title,
> >> >> > textarea
> >> >> > {background-color:#fff;border:1px solid #bbb;}
> >> >> > input[type=text]:focus, input[type=password]:focus, input.text:focus,
> >> >> > input.title:focus, textarea:focus {border-color:#666;}
> >> >> > select {background-color:#fff;border-width:1px;border-style:solid;}
> >> >> > input[type=text], input[type=password], input.text, input.title,
> >> >> > textarea,
> >> >> > select {margin:0.5em 0;}
> >> >> > input.text, input.title {width:300px;padding:5px;}
> >> >> > input.title {font-size:1.5em;}
> >> >> > textarea {width:390px;height:250px;padding:5px;}
> >> >> > form.inline {line-height:3;}
> >> >> > form.inline p {margin-bottom:0;}
> >> >> > .error, .alert, .notice, .success, .info
> >> >> > {padding:0.8em;margin-bottom:1em;border:2px solid #ddd;}
> >> >> > .error, .alert
> >> >> > {background:#fbe3e4;color:#8a1f11;border-color:#fbc2c4;}
> >> >> > .notice {background:#fff6bf;color:#514721;border-color:#ffd324;}
> >> >> > .success {background:#e6efc2;color:#264409;border-color:#c6d880;}
> >> >> > .info {background:#d5edf8;color:#205791;border-color:#92cae4;}
> >> >> > .error a, .alert a {color:#8a1f11;}
> >> >> > .notice a {color:#514721;}
> >> >> > .success a {color:#264409;}
> >> >> > .info a {color:#205791;}
> >> >> > 
> >> >> >   
> >> >> >   
> >> >> > 
> >> >> >   
> >> >> >   
> >> >> >   
> >> >> > 
> >> >> >   Enter information
> >> >> >   
> >> >> > 

Re: "Writing your first Django app" Tutorial Question

2012-10-12 Thread Jason Sibre
Hi Rick,
I'll try to explain, but it's really more about Python than Django...

(I'm not familiar with the tutorial app, so I'm basing my answers on what code 
you copied into your email.)

That import of Poll that you see in details.py doesn't even enter into it.  
It's only used on the line that says "p = get_object_or_404(...".  In fact (and 
here's where my newness in Django shows), I don't think that Poll is even 
visible (in scope) in the detail.html template.  But the Poll instance that was 
put passed to "render_to_response(..." is.  The "p" variable had an instance of 
a Poll, and it was bound to the name 'poll' in that bit "{'poll':p}".

Once in the template, it's just a matter of traversing the objects.  
poll.choice_set.all presumably returns a set (or list?) of Choice instances, 
which are bound to the variable "choice".  Then, it's just a matter resolving 
the "choice" name on that instance.  

Since Python is a dynamically typed language, so you don't need to declare the 
data type of "choice" before assigning values to it, so there's no need to do 
something like 
Choice choice = null
which you might need to do in a language like Java.  If you *did* need to do 
that, you'd have to import Choice so that the above line would work.  Since you 
*don't* need to do that, and you're never referencing "Choice" in the template, 
there's no need to import it. 

Maybe it would help to think of import as a special kind of assignment operator 
(that's a gross simplification, but it may help as a metaphor)...  Writing 
from polls.models import Choice
is a bit similar in concept to saying something like
Choice = polls.models.Choice   #make a local reference the Choice class in the 
polls.models package.

Does that help at all?  
This is all way more related to basic Python than to Django, and you may find 
it helpful to run through a Python tutorial (http://docs.python.org/tutorial/ 
for example)

Jason


On Oct 12, 2012, at 5:06 AM, Rick Chong wrote:

> Hi, I have just started learning programming and I am following the creating 
> a poll app tutorial at:
> https://docs.djangoproject.com/en/1.4/intro/tutorial03/
> 
> I hope that someone has attempted this tutorial and is able to help me on 
> some very beginner questions:
> 
> In this app, we defined 2 classes in the model - Poll & Choice:
> import datetime
> from django.utils import timezone
> from django.db import models
>   
> # Create your models here.
> class Poll(models.Model):
>   question = models.CharField(max_length=200)
>   pub_date = models.DateTimeField('date published')
>   def __unicode__(self):
>   return self.question
>   def was_published_recently(self):
>   return self.pub_date >= timezone.now() - 
> datetime.timedelta(days=1)
>   was_published_recently.admin_order_field = 'pub_date'
>   was_published_recently.boolean = True
>   was_published_recently.short_description = 'Published recently?'
> 
> class Choice(models.Model):
>   poll = models.ForeignKey(Poll)
>   choice = models.CharField(max_length=200)
>   votes = models.IntegerField()
>   def __unicode__(self):
>   return self.choice
>  
> 
> Then in views.py... I have the following code:
> from django.shortcuts import render_to_response, get_object_or_404
> from polls.models import Poll
> 
> def detail(request, poll_id):
>   p = get_object_or_404(Poll, pk=poll_id)
>   return render_to_response('polls/detail.html', {'poll': p})
> 
> 
> 
> Then in my template, detail.html. I have the following code:
> {{ poll.question }}
> 
> {% for choice in poll.choice_set.all %}
>   {{ choice.choice }}
> {% endfor %}
> 
> 
> 
>  
> The scripts run My question:
> In views.py, I only import Poll class from model... why am I able to display 
> choice, which is a variable under Choice class?
> 
> 
> Thank you very much.
> 
> 
> 
> 
> Rick
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/2vqJuWiYVuIJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.